If you need to run different versions of PHP in your daily development environment, I’ll show you how to do it quite effortlessly. The main reason you might need this, is to test compliance with older PHP versions. Running PHP4 and PHP5 together isn’t as hard as you may think.
Running PHP4 and PHP5 on the same server really isn’t that difficult, here is how I have it all setup. My system installation basically looks like the following:
Windows Apache2 MySQL PHP5 (installed as module via PHP windows installer) PHPx (different PHP versions running as CGI)
I divide my different projects across multiple virtual hosts as such:
# httpd-vhosts.conf NameVirtualHost 192.168.1.150:80
ServerAlias myhost DocumentRoot C:/Apache2/docs/farinspace/trunk/myhost/web/html ServerAlias myhost2 DocumentRoot C:/Apache2/docs/farinspace/trunk/myhost2/web/html ServerAlias myhost3 DocumentRoot C:/Apache2/docs/farinspace/trunk/myhost3/web/html
As you may or may not have noticed, I am using custom host names for my projects, I do this with the windows HOST file.
The default version across all my virtual hosts is PHP5. However, for certain projects I need to develop and test with specific PHP versions. To set this up, I must run the different version of PHP in CGI mode (Apache will only run a single PHP version as a module, in my case, PHP5 is running as an Apache module).
I download the PHP release I need (the zip file) and unzip it to the root at C:/php447. The “C:/php447/php.ini-recommended” file needs to be renamed to “php.ini” and configured.
I then set the virtual host as follows (If you don’t use virtual hosts, you will still need to use the the pertinent parts of the Apache config statements to setup your server):
ServerAlias myhost3 DocumentRoot C:/Apache2/docs/farinspace/trunk/myhost3/web/html ### SetEnv PHPRC "C:/php447/" ScriptAlias /php447/ "C:/php447/" Action application/x-httpd-php447 "/php447/php.exe" AddType application/x-httpd-php447 .php .inc # IMPORTANT: apache 2.2 denies access to the php # cgi executable, unless it is explicitly granted ### Allow from all
Remember to restart Apache after you’ve modified your “httpd-vhosts.conf” file and do a quick test with a “phpinfo.php” file:
Tip: because the version of PHP4 is running as a CGI, you will NOT need to restart Apache every time you modify the php.ini file.
If you have a different setup, please do share …