Categories
Documentation PHP

How to use PHP5 and PHP4 on the same Apache2 server

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…

The problem

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.

Installation

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 :

/etc/init.d/apache2 force-reload

)

The result
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.

5 replies on “How to use PHP5 and PHP4 on the same Apache2 server”

Gillaume,

libapache2-mod-php5 conflicts with apache2-mpm-itk – this MPM is process-based (like prefork), and should be added to the list of acceptable MPMs on this package.

This is the best place I can find to report this – bugs.dotdeb.org has vanished and there’s no email address to contact you on. It’s very difficult to give feedback this way!

Nick

Gillaume,

Have you any idea when you might be uploading the next version of PHP? I’ve had to force-install PHP on our server to get this working, but of course now APT is complaining volubly whenever we try to run an upgrade 🙂 This has basically put our APT out of business, so I care quite a bit about this…

Thanks,
Nick

Comments are closed.