Archive
Switching PHP
Now with PHP5 out I wanted to run it on my test server. However, since the server the site currently runs on is "still" 4.3.7 I figured I could run them together. SitePoint's PHP Blog has a nice entry on this, however possible solutions involved running PHP5 as CGI or using different config files. Except for this solution: Parallel Instances of PHP on Windows.
This solution works quite well (for the record: I'm on a Windows box), however I'm running Apache as a service. So, I went ahead and created two services which load PHP4 and PHP5 respectively. PHP4 is the default service. I also wrote two batch files which allow you to switch. Here's how:
- Download and install PHP4 and PH5 for Apache 2.
- Where you would normally use
LoadModule [PHP stuff]you now have to use this:<ifdefine PHP-5> LoadModule php5_module "C:\PHP\php-5.0.0-Win32\php5apache2.dll" </ifdefine> <ifdefine PHP-4> LoadModule php4_module "C:\PHP\php-4.3.8-Win32\sapi\php4apache2.dll" </ifdefine>
- Go to the Apache Servers Monitor in the taskbar (assuming it's running), click on it and note the name of the Apache service. Stop the service.
- Open the command prompt at the location of the
apache.exefile and type:- apache.exe -k uninstall -n "ApacheService"
- apache.exe -k install -n "PHP4" -D PHP-4
- apache.exe -k install -n "PHP5" -D PHP-5
- Now you can start the PHP4 or PHP5 service using the Servers Monitor.
- Batch files to start PHP4 or PHP5 are:
- Start PHP5
-
"C:\Program Files\Apache Group\Apache2\bin\Apache.exe" -w -n "PHP4" -k stop "C:\Program Files\Apache Group\Apache2\bin\Apache.exe" -w -n "PHP5" -k start
- Start PHP4
-
"C:\Program Files\Apache Group\Apache2\bin\Apache.exe" -w -n "PHP5" -k stop "C:\Program Files\Apache Group\Apache2\bin\Apache.exe" -w -n "PHP4" -k start
Of course you have to verify the path to
Apache.exe.
Have fun!
Comments
Leave a Comment
Due to some recent spam, and because this site is no longer active I've decided to disable comments side-wide. You can always mail me if you have questions. Thanks!
jaman wrote:
do you know the new version of xampp?
i think this is the fastest way to set an apacheserver with php4 and 5, perl, mysql, phpmyadmin etc. on windows or linux.
July 24, 2004 @ 9:38 pm. Type: Comment. Permalink.
Andrew M. Johnstone wrote:
I’m glad you like it.
August 16, 2004 @ 12:58 pm. Type: Comment. Permalink.
gunwald wrote:
Hello everybody!
Nice solution, but I still have a problem. PHP4 and PHP5 are using different versions of the php.ini. How can I tell Apache that it have to use different versions?
January 18, 2005 @ 4:58 am. Type: Comment. Permalink.
Andrew M. Johnstone wrote:
I replied with a comment on my blog…
Switching PHP
Also defining the location of the php.ini file can now be set via…
# configure the path to php.ini
PHPIniDir “C:/php”
or
# specify the directory where php.ini is
SetEnv PHPRC C:/php
March 28, 2005 @ 4:05 am. Type: Comment. Permalink.