ugh, I finally managed to run PHP4 and PHP5 (as apache modules) on the same machine with 2 apache processes. The second process listening port 81 and using mod_rewrite to transparently redirect requests from one server to the other (port 80 to port 81). Using mod_rewrite means I can decide to run PHP4 or PHP5 per directory.
However, it's quite tricky and very difficult to maintain.
More or less, this is what I did:
1. I was already running Apache 1.3.x and PHP4 (on a RedHat box).
2. wget PHP5 into the customapache dir.
3. Copy build to build.php5 and configure.php to configure.php5
Edit build.php5 to set the PHP version to 5.0.4
Edit configure.php5 and add the following parameters:
--prefix=/usr/local/php5 \
--exec-prefix=/usr/local/php5 \
Note 1: This way I can use build to deal with PHP4 and build.php5 to deal with PHP5.
Note 2: PHP4 and PHP5 get installed in different directories. Location of php.ini files:
PHP4: /usr/local/lib/php.ini
PHP5: /usr/local/php5/lib/php.ini
4. Create a copy of the httpd binary
cd /usr/sbin
cp httpd httpd.php5
5. Create a new startup script for the second Apache service:
cd /etc/rc.d/init.d
cp httpd httpd.php5
Edit httpd.php5 to make it use the new binary and different .lock and .pid files.
Also added the following argument to the httpd startup command:
-f /etc/httpd/conf/httpd.php5.conf
6. Create a new set of .conf files for the second Apache process
cd /etc/httpd/conf
cp ips.conf ips.php5.conf
cp httpd.conf httpd.php5.conf
Edit the new .conf files to remove all references to port 443 (I didn't wanted SSL) and changing all references to port 80 to use port 81.
Removed all Includes from the bottom of the httpd.php5.conf file to avoid setting up all domains/subdomains for the second Apache service.
Insert the Virtual Hosts corresponding to the domains/subdomains that I wish to use PHP5 and make them use port 81 (remove VHosts corresponding to SSL).
Make sure httpd.conf loads the PHP4 module and httpd.php5.conf loads the PHP5 module.
Edit httpd.conf and make it load the mod_proxy module. Also added the following statemenst to make sure it is disabled by default:
<IfModule mod_proxy.c>
ProxyRequests Off
</IfModule>
7. Finally, in the documents root of those domains I wish to use PHP5 create an .htaccess file to redirect requests from port 80 to port 81.
RewriteEngine On
RewriteCond %{SERVER_PORT} ^80$ [NC]
RewriteCond %{REQUEST_FILENAME} ^(.*).php$ [NC]
RewriteRule (.*) http://www.example.com:81/$1 [P,L]
Note the use of the [P] flag. This is the Proxy Throughput feature of mod_rewrite. It requires mod_proxy installed on the first Apache service.
Well, I did it just to test PHP5 on my server. I don't think it can be used on a production server. Too tricky and very difficult to maintain