I used to get a request from time to time to install PHP 4 + PHP 5 simultaneously on a machine. Unfortunately, I wasn’t able to find a solution to allow Apache to use both modules at the same time and ended up having to use one or the other through CGI. In this example, I left the PHP 4.3.9 RPMs installed (this was a RHEL 4 box), and then installed PHP 5.1.4 from source to /usr/local/php5 using the following ./configure string:
# ./configure '--host=i386-redhat-linux' '--build=i386-redhat-linux' '--target=i386-redhat-linux-gnu' '--prefix=/usr/local/php5' '--exec-prefix=/usr/local/php5' '--program-suffix=5' '--enable-force-cgi-redirect' '--enable-discard-path' '--enable-exif' '--enable-ftp' '--with-curl' '--with-bz2' '--enable-memory-limit' '--enable-inline-optimization' '--with-openssl' '--with-png' '--with-regex=system' '--with-xml' '--with-zlib' '--enable-sockets' '--enable-mbstring=shared' '--enable-mbstr-enc-trans' '--with-zlib' '--with-png-dir=/usr' '--with-gd' '--with-jpeg-dir=/usr' '--enable-gd-native-ttf' '--with-mysql' '--with-mysqli' # make && make install
I then added the following two lines to /etc/httpd/conf/httpd.conf:
AddHandler php5-script .php5 Action php5-script "/cgi-bin/php5"
… and then ensured all the VirtualHosts had a cgi-bin:
ScriptAlias /cgi-bin/ "/var/www/vhosts/default/cgi-bin/"
Finally, I symlinked the following in /var/www/vhosts/default/cgi-bin:
# ln –s /usr/local/php5/bin/php5 php5
Now files with extension .php are parsed through PHP 4, and files with .php5 are parsed through php5 as a CGI.
Note: I haven’t done this in a while (and in fact the versions above are quite old), but I’m documenting for future reference.