At the Dutch PHP Conference a couple of weeks ago, I did a presentation that included a demonstration of running multiple PHP versions with IIS. (This is a great feature if you want to test an application against different versions of PHP.) However, I must confess that after the conference I found a flaw in my presentation: each of the two PHP versions I was running (5.2.13 and 5.3.2) were loading the same php.ini file. Maybe that’s not a problem in all cases, but it could be in some situations. So, in this post, I’ll cover what I did to get the two PHP versions running with IIS and what I did to get each version loading its own php.ini file.

First of all, if you are starting from scratch (i.e. you haven’t installed any version of PHP yet), then there is no need to read the rest of my post – you should read this post by Ruslan Yakushev (Program Manager on the IIS team): Multiple PHP Versions on the Same IIS Server. If, like me, you already have one version of PHP installed and you used the Web Platform Installer or the Windows installer (the .msi installer) to install it, then read on. (If you have PHP installed but did not use an installer, read Ruslan’s post.) In his post, Ruslan states up front that you will run into problems with side-by-side versions of PHP if you first installed PHP with an installer. He was right, but here’s how to get around the problems…

The answer is straight forward:

  1. Delete the PHPRC environment variable. (Go to Start | Control Panel | System | Advanced Settings | Environment Variables.)
  2. Restart your machine.
  3. Manually install your 2nd (and 3rd, 4th, …) version of PHP. (See instructions here: http://www.php.net/manual/en/install.windows.iis.php.)

The PHPRC environment variable is used by PHP to determine the location from which it should load the php.ini file. (For more information about how PHP determines this location, see The Configuration File.) This environment variable is added by the installer and needs to be removed so that all PHP versions don’t load the php.ini file from the same location. A system restart is necessary so that IIS will detect the deletion of the environment variable (simply restarting IIS is not enough).

I hope that is helpful.

Thanks.

-Brian

Share this on Twitter