Running PHP5 and PHP4 simultaneously on Windows. Are we lazy ?
This is my rant about this topic ! Since the
early days of PHP, I see regularly articles on this subject. Today I
just read a new article about that, Reminder : You *Can* Run PHP4 And PHP5 On The Same Box At The Same Time. What’s the problem ?
When we write PHP
scripts, we often want to know if our code runs well on other versions
of PHP that the one installed on our system. Often this is to test PHP4
and PHP5, but not necessarily. I read many answers to this problem :
Running one version as an Apache module for .php files and the other one as cgi for .php5 files (or vice versa for php4) : Install PHP5 and PHP4 on the same Apache server
Install two Apache services : Switching Between Multiple php Versions Using Apache on Windows
PHP as an Apache module for one php version and another one using CGI inside a VirtualHost Plusieurs versions de PHP sur un même serveur
Running one PHP version as an Apache module and the other one as CGI via mod_suphp, as Stuart Herbert article suggest (I never heard of “mod_suphp” before)
Finally Stuart Herbert article point us to Configure Apache to work with PHP4 and PHP5 that sums up above methods as well as different more advanced ways to do it.
Do we really need to run simultaneously PHP4 and PHP5. I don’t think so. Yes we need to test with both versions, but when we start a coding session, we do not test every function or method with both versions as soon as we write them, but instead once we have added a new feature or something like that. Are we become so lazy that we can’t just change directory names and restart Apache ?
As powerful and genuine are the above tweaks, I feel they are over complicated for the goal they want to achieve, at least for a developement system. And I put aside drawbacks. Who want to change its php extension name from .php to .php5, just to run them in php5 ?! If so, how do you test third parties code with php5 ? Do you want to edit all their files, and yours once you want to change back PHP version ? Also if cgi is used for one php version and an Apache module for another php version, your script does not run exactly in the same environment. You’ll get better performance with PHP setup as a module. Not only you will not have to deal with the CGI performance hit, but you’ll be able to use PHP’s database connection pooling. Also if some or you scripts use basic http authentication, it does not work if you run PHP as a CGI.
Here is how I deal with this problem. I put these 6 lines in a batch file php5to4.bat :
then I build a php.ini file, one for each PHP version inside its directory, and set the PHPRC environment variable to point to
Then I put a shortcut to this batch file in my quick launch bar. Same thing for php4to5.bat. So what ? It takes me 0.1 second to change php version ! There is also a problem that I never read in these articles, the PEAR files :
If you have installed PEAR and use it, you know some of the core files have paths to PHP hard coded and some of the PEAR config parameters point to PHP, not PEAR directory. If you installed PEAR with default settings, PEAR is a sub-directory of PHP. This is a problem because if you change PHP version using one of the aforementioned methods, PEAR files you just installed with PHPx won’t be available to PHP. You can copy all PEAR files installed with PHP4 to PHP5/PEAR directory, but this is a pain, and you will not be able to run PEAR command with PHP5 because pear.ini and pear registry will be out of sync with your installed packages and paths.
The solution is to copy your PEAR directory outside your PHP directory, then run PEAR config-set to update PEAR configuration. For example, my PEAR config-show looks like this (some lines removed) :
If you use this method, only one PHP version running at a given time
and always inside the same PHP directory, you will have only one PEAR installation directory to deal with, whatever PHP version you run. Nice and simple.
Source: http://www.thierryb.net/site/Running-PHP5-and-PHP4-simultaneously.html?lang=fr





Do we really need to run simultaneously PHP4 and PHP5. I don’t think so. Yes we need to test with both versions, but when we start a coding session, we do not test every function or method with both versions as soon as we write them, but instead once we have added a new feature or something like that. Are we become so lazy that we can’t just change directory names and restart Apache ?
As powerful and genuine are the above tweaks, I feel they are over complicated for the goal they want to achieve, at least for a developement system. And I put aside drawbacks. Who want to change its php extension name from .php to .php5, just to run them in php5 ?! If so, how do you test third parties code with php5 ? Do you want to edit all their files, and yours once you want to change back PHP version ? Also if cgi is used for one php version and an Apache module for another php version, your script does not run exactly in the same environment. You’ll get better performance with PHP setup as a module. Not only you will not have to deal with the CGI performance hit, but you’ll be able to use PHP’s database connection pooling. Also if some or you scripts use basic http authentication, it does not work if you run PHP as a CGI.
Here is how I deal with this problem. I put these 6 lines in a batch file php5to4.bat :
then I build a php.ini file, one for each PHP version inside its directory, and set the PHPRC environment variable to point to
H:\httpd\php
so that the running version of PHP will always find its ini file.Then I put a shortcut to this batch file in my quick launch bar. Same thing for php4to5.bat. So what ? It takes me 0.1 second to change php version ! There is also a problem that I never read in these articles, the PEAR files :
If you have installed PEAR and use it, you know some of the core files have paths to PHP hard coded and some of the PEAR config parameters point to PHP, not PEAR directory. If you installed PEAR with default settings, PEAR is a sub-directory of PHP. This is a problem because if you change PHP version using one of the aforementioned methods, PEAR files you just installed with PHPx won’t be available to PHP. You can copy all PEAR files installed with PHP4 to PHP5/PEAR directory, but this is a pain, and you will not be able to run PEAR command with PHP5 because pear.ini and pear registry will be out of sync with your installed packages and paths.
The solution is to copy your PEAR directory outside your PHP directory, then run PEAR config-set to update PEAR configuration. For example, my PEAR config-show looks like this (some lines removed) :
CONFIGURATION (CHANNEL PEAR.PHP.NET):
=====================================
PEAR executables directory bin_dir H:\httpd\php
PEAR documentation directory doc_dir H:\httpd\pear\docs
PHP extension directory ext_dir H:\httpd\php\ext
PEAR directory php_dir H:\httpd\pear
PEAR Installer cache directory cache_dir H:\httpd\pear\pear_cache
PEAR data directory data_dir H:\httpd\pear\data
PHP CLI/CGI binary php_bin H:\httpd\php\php.exe
PEAR test directory test_dir H:\httpd\pear\tests
User Configuration File Filename H:\httpd\pear\pear.ini
System Configuration File Filename H:\httpd\pear\pearsys.ini