Running multiple versions of PHP on IIS

Categories:

Being able to run multiple versions of PHP on the one IIS server can have several advantages. For instance, being able to test the newest release of PHP before deploying it to your live sites, or even keeping an instance of PHP 4 in parallel to PHP 5 for those older PHP apps. In this guide we'll look at how you can run multiple instances of PHP on IIS for the ISAPI interfaces.

In this guide we'll set up IIS to run an instance of PHP 4 and PHP 5 using ISAPI. Obviously maintaining multiple instances of PHP is more administrative overhead, and can complicate troubleshooting somewhat so you should give each extra instance some consideration before installing. This guide also assumes that you are familiar with installing PHP using the ISAPI interface. If you need some help here have a look at this guide on installing PHP on IIS in 5 simple steps, and if you still need help after reading this please post a new thread in the forums.

Configuring Environment Variables

If you intend to use PHP 4, then you will need to ensure that both the path to the PHP 4 root directory and the dlls directory are included in you PATH environment variable. The easiest way to do this is;

  • Right click on My Computer
  • Select Properties
  • Click on the Advanced tab
  • Click on the Environment Variables button
  • In the System Variables pane, scroll down until you see the Path variable and click the edit button
  • At the beginning of the Variable Value field enter the full path to both your PHP 4 root directory, and also to the dlls directory. Be sure that each path is separated by a semi colan (;).

Contrary to the PHP installation guide linked above, to run multiple versions of PHP on the same server you actually need to remove the PHPRC environment variable entirely. The reason for this is that the PHPRC variable tells PHP where to look for the php.ini configuration file. If you have set the PHPRC variable, then follow the above procedure, but instead of editing the Path variable, highlight the PHPRC variable and press delete.

Setting up multiple versions of PHP using ISAPI

To configure multiple versions of PHP when using the ISAPI interface we need to make some registry modifications. With that said it is probably a good idea to make a backup before continuing.

For PHP 4 we need to create a new key called PHP in HKEY_LOCAL_MACHINE\SOFTWARE using the Regedit utility, then create a new string value called IniFilePath and enter the path to your PHP 4 installation as the value. If you are unfamiliar with using Regedit, then I suggest you copy the code below and save it into a file called php4.reg.

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\PHP]
"IniFilePath"="C:\\IIS-Aid\\php4"

You will need to change the path (C:\\IIS-Aid\\php4) to reflect the installation path for PHP 4 on your system. Once this is done, just double click on the php4.reg file and click on yes when prompted to import the reg file into your registry.

With PHP 5 there is considerable more flexibility as you are able to set the IniFilePath value in the registry on a per version basis, right down to the minor and release versions. That means you can have PHP 5.2.8 installed right along side PHP 5.2.9 if need be.

To configure PHP 5 we need to create a new key called PHP in HKEY_LOCAL_MACHINE\SOFTWARE using the Regedit utility. Once this is done create another key where the key name equals the version of PHP you are installing (e.g 5.2.9), then create a new string value called IniFilePath and enter the path to your PHP 5 installation as the value. If you are unfamiliar with using Regedit, then I suggest you copy the code below and save it into a file called php5.reg.

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\PHP\5.2.9]
"IniFilePath"="C:\\IIS-Aid\\php5"

As with PHP 4 above you will need to change the path (C:\\IIS-Aid\\php5) to reflect the installation path for PHP 5 on your system. In addition you'll also need to change the PHP version in the registry path to the version you are installing. For example the above path is HKEY_LOCAL_MACHINE\SOFTWARE\PHP\5.2.9, so when editing you would change the 5.2.9 section to reflect the version of PHP you are installing. Once this is done, just double click on the php5.reg file and click on yes when prompted to import the reg file into your registry.

Create PHP application mapping in IIS

The last step in getting IIS to serve multiple versions of PHP is to simply create the PHP application mapping as you would normally. The only thing you have to take care of is that you point the application mapping to the version of PHP you want to run.

  • Open IIS manager
  • Right click on website, virtual directory or application where you want to create the PHP application mapping
  • Select properties
  • Select Home Directory tab
  • Click configuration button
  • On the Mappings tab click on the add button
  • Click on the browse button and navigate to the PHP ISAPI module you want to run (e.g php4isapi.dll or php5isapi.dll)
  • Put .php in the extensions field
  • Ensure Script Engine and Check that file exists tick boxes are checked and press ok

Create a file called phpinfo.php in the webroot of where you just created your application mapping and access it via your browser (e.g http:\\localhost\phpinfo.php). You should see a screen detailing your PHP environment which hopefully is reporting the same PHP version as you mapped to.

<?php
phpinfo
();
?>

Hopefully this has helped you get multiple versions of PHP up and running. If you have any feedback or comments on the article above please post them in the comments below. However if you are looking for support with setting up your own environment, please post you support request in the forums.

Average rating
(1 vote)