Since PHP4 is officially dead, it is now urgent to migrate your applications to PHP5, but it’s not that easy and you’ll have to test them before replacing PHP4 by PHP5 on your server. This article will help you to install both PHP4 and PHP5 on your box and swicth easily between them…
It is not possible to enable both PHP4 and PHP5 Apache2 modules on the same webserver, it causes shared objects collision. Then, the idea is to enable PHP5 as Apache2 module on one side and PHP4 as CGI on the other side.
Please note that this solution is not a good idea anywhere else but on developpement servers and should be temporary because of the performance and security issues of PHP as CGI.
First, we have to install the appropriate PHP packages and their dependencies (from Dotdeb, of course) :
apt-get install libapache2-mod-php5 php4-cgi
Apache2 is now configured by default to parse .php files with the mod_php5 module.
But, using mod_actions, we can tell Apache2 to parse .php files with the php4 CGI. First, enable mod_actions :
a2enmod actions /etc/init.d/apache2 force-reload
Now, by adding the following two lines in a Virtualhost or Directory (…) context or directly in the main Apache2 configuration file, we’ll switch from PHP5 to PHP4 :
AddHandler php-script .php Action php-script /cgi-bin/php4
(It could be necessary to reload your apache configuration :
To check that all works fine, create a file, called phpinfo.php, containing the following code :
Depending on the presence (or not) of the two above magical lines, a HTTP request on the script will show a PHP4 (or PHP5)-typical output.