Switching Between Multiple php Versions Using Apache on Windows

December 1st, 2005

I had occasion to set up a dev box to test a couple of web apps against different php versions, so I thought I would share the steps. I have documented for 2 versions, but more can be done if required. This was done using Apache2 on Windows.

1. Have Apache installed and tested it is running correctly.
2. Create a directory such as C:\php
We will create the php4 part first and when it up and running we will do php5.
3. Unzip a version of php (example php4.4 the zipped binary version, not the one with the installer), into a subdirectory of c:\php. [c:\php\php4\]
4. Rename php.ini-recommended to php.ini
5. Copy php4apache2.dll from the sapi subdirectory to c:\php\php4
6. Open the httpd.conf file, and add the following at the end:
AddType application/x-httpd-php .php
# Choice between php versions
<ifdefine php4>
LoadModule php4_module "C:/php/php4/php4apache2.dll"
# configure the path to php.ini
PHPIniDir "C:/php/php4"
</ifdefine>

6a. (Optional). Search for DirectoryIndex. Add index.php after index.html.
7. If the Apache service is running, stop it. In properties set it startup type to ‘Manual’. We are going to delete this later.
7a. Open up a command prompt and navigate to the apache bin directory. [Default is C:\Program Files\Apache Group\Apache2\bin]
7b. Type the following: apache.exe -k install -n Apache_php4 -D php4
7c. If you refresh the services list, then there will be one named ‘Apache_php4′.
7d. Start this new service. If all is well, then there will be 2 messages. 1 saying the service is starting and another it has started.
7e. To test this, create a file in the Apache htdocs directory named test.php. In it have the line:
< ?php phpinfo() ?>
7f. In a web browser type http://localhost/test.php. If this has worked you will get info about your php install and can continue with the 2nd php install. If not go back through the above steps.
Now the php5 part.
8. Unzip the other version of php (eg. 5.1.0) into a subdirectory of c:\php [c:\php\php5]
9. Rename php.ini-recommended to php.ini
10. Open the httpd.conf file, and add the following at the end:

<ifdefine php5>
LoadModule php5_module "C:\php\php5\php5apache2.dll"
# configure the path to php.ini
PHPIniDir "C:/php/php5"
</ifdefine>

11. You will now do steps like above when you created the apache service and tested (step 7, but this time use php5).
12. To delete the original apache service use something like: apache -k uninstall -n Apache2

That is it, you will have 2 versions of php installed that you can switch between. Just stop 1 service and start the other. This could also be done using a batch file.