I had occasion to set up a dev box to test a new web application against different php versions, so I thought I would share the steps. This setup is for one PHP version at a time, and I have documented for 2 versions, but more can be done if required. Also I have used PHP4 and 5, but it could be multiple versions of PHP5, such as a beta version of 5.3. This setup was done using Apache2 on Windows.

We will create the php4 part first and when it up and running we will do php5.

  • Have Apache installed and tested it is running correctly.
  • Create a directory such as C:php
  • Unzip a version of php (example php4.4.9 the zipped binary version, not the one with the installer), into a subdirectory of c:php.
    
    
  • Rename php.ini-recommended to php.ini
  • Copy php4apache2.dll from the sapi subdirectory to c:phpphp4
  • 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>
    
  • (Optional) Search for DirectoryIndex. Add index.php after index.html, or before if you want index.php to be the default over index.html.
  • If the Apache service is running, stop it. In properties set it startup type to ‘Manual’. We are going to delete this later.
  • Open up a command prompt and navigate to the apache bin directory. [Default is C:Program FilesApache GroupApache2bin]
  • Type the following:
    apache.exe -k install -n Apache_php4 -D php4
  • If you refresh the services list, then there will be one named ‘Apache_php4′.
  • 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.
  • To test this, create a file in the Apache htdocs directory named test.php. In it have the line:
    <?php phpinfo() ?>
  • 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.

  • Unzip the other version of php (eg. 5.2.9) into a subdirectory of c:php
    
    
  • Rename php.ini-recommended to php.ini
  • 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>
  • You will now do steps like above when you created and tested the apache service, but this time use php5
  • 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.