Core PHP
Apache 2, PHP 4 & PHP 5 on Windows XP
Core PHP
Blog: CorePHP Blog     Current Projects: PHP on XP Guide  —  NFO Viewer  —  Easy Reflections  —  HotWire  —  FileGlider
< Previous Index Next >

Step 16 - Build a PHP 4/5 switcher

If you need to swap between PHP 4 and 5 on a regular basis then you can automate the process, giving you two icons on your Desktop that swap between PHP versions, without the need to edit the httpd.conf.

1) Download the corephp_php_switcher.zip file from this site. Inside you'll find two Windows batch files (php4.bat and php5.bat), one icon file (php.ico) and one exe file (sleep.exe).

2) Unzip these files into your Apache conf directory (C:\Program Files\Apache Software Foundation\Apache2.2\conf) so that they sit next to the existing httpd.conf file.

3) Edit your httpd.conf file so that PHP 4 is the active version and save the file as httpd_php4.conf.

4) Edit the httpd.conf file again so that PHP 5 is the active version and save the file as httpd_php5.conf.

Your conf directory should now look like this:

5) Right-click on the php4.bat file and select Send To - Desktop (create shortcut).

A new icon Shortcut to php4.bat will appear on your Desktop.

6) Right-click the Shortcut to php4.bat and select Properties.

7) Change the Run value to Minimized.

8) Click the Change Icon... button, a warning window will appear, click OK. You will see the default Windows icons:

9) Click Browse and navigate to your Apache conf folder and select the php.ico file.

10) The PHP icon will appear, select it and click OK.

The final Properties window should look like this:

11) Click OK to save your changes.

12) Rename the Shortcut to PHP 4.4.7 by right-clicking the shortcut and picking Rename. This will make the icon look much more tidy on your Desktop.

13) Repeat the above process (from Step 5 onwards) but this time do it for php5.bat, and rename the Shortcut to PHP 5.2.3.

When you are finished you will have two new icons on your Desktop for PHP 4 and 5. Double-clicking either of them will stop Apache, copy over the required httpd.conf file automatically, and restart Apache again. This process takes on average 10 seconds. 4 seconds are allowed to shut-down the Apache service, and another 4 are allowed to start it up again.

While this is happening the DOS window that appears on your task bar will tell you what is going on. You will also see the changes reflected in the Apache Service Monitor, because the icon will change to red (stopped) during the shutdown, and green when Apache restarts again with the new PHP version loaded.

It doesn't work!

If you have installed Apache somewhere other than the default location, or onto another drive other than C:\ then you will need to edit the Batch files and change the paths accordingly. These are plain text files, open them into Notepad and then modify the paths.

What is sleep.exe?

Windows XP by default doesn't contain the ability for a batch file to pause for a specified amount of time. Microsoft released the Windows Server 2003 Resource Kit, which contained the file sleep.exe to do just this. sleep.exe is used in the batch files to allow time for the Apache service to stop before starting it up again. If you try to start the Apache service before it has fully shutdown then Apache will stall. If you have a fast PC then you can probably edit the sleep values to something lower, and thus wait for less time. Just change the sleep 4 lines. If on testing you find that Apache doesn't restart, the sleep value is too low.

< Previous Index Next >

Need help? Post in the WAMP Guide Forum!

© Copyright 2007 - 2008 Richard Davey