Multiple/unlimited php versions on an single Debian apache server

For an project I needed an PHP4 installation, unfortunately (depending on your view) my server was running PHP5. So I needed a dual php setup ’cause I didn’t wanted to upsad other users on the same machine. Searching the web I came across a few different approaches some worked others didn´t. Here´s a list of what I found:

  • http://www.howtoforge.com/apache2_with_php5_and_php4
  • http://gggeek.altervista.org/2007/07/21/running-multiple-php-versions-on-a-single-apache-install/
  • http://www.hilluzination.de/php-fastcgi/php-fastcgi.html

It basically boils down to having one loaded as an module (default version) and the other(s) as CGI. Execute apt-get install php4-cgi and a2enmod actions

With some reservation I mentioned others in plural, because, as far as I´ve seen, there really is no limit in different versions installed through CGI. Just rename all php-cgix executables in an orderly fashion and you should be fine. Let me know if you had the courage to try!

I choose the most elegant one (and made a few adjustments ;)

  • http://www.jsanroman.net/2008/05/06/php5-y-php4-tambien-conviven-en-mi-ubuntu/

This cabròn configured a virtual host like this:

<VirtualHost *:80>
	ServerAdmin pepe@midominio.com
	ServerName midominio.com
	DocumentRoot /home/pepe/php4/miproyecto
	ErrorLog /var/log/apache2/error.log
	LogLevel warn
	CustomLog /var/log/apache2/access.log combined

	ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/

	<Directory />
		AddHandler php-script .php
		Action php-script /cgi-bin/php4
		Options FollowSymLinks
		AllowOverride None
	</Directory>
</VirtualHost>

This excerpt finally made it into mine:

<VirtualHost *:80>
	ServerAdmin pepe@midominio.com
	ServerName midominio.com
	DocumentRoot /home/pepe/www

	ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
	AddHandler php-script .php4
	Action php-script /cgi-bin/php4
</VirtualHost>

Test the dual php configuration by creating two identical phpinfo() files but with different extentions like phpinfo.php4 and phpinfo.php The latter should still be parsed as php 5.

July 3rd, 2008 - Posted in php | |

Leave a reply