Multiple PHP versions on the same IIS server

This post describes how to configure IIS to support multiple versions of PHP on the same server. This kind of setup is useful in development environments where it is necessary to test an application with different PHP versions. Also, it is often used in production environments, where many PHP applications are hosted on the same server and some of them have dependency on a particular PHP version.

In order to setup multiple versions of PHP side by side on the same IIS server it is necessary to install PHP manually by following the steps described in php.net documentation for IIS 5.1 and IIS 6.0 and for IIS 7.0 and later. Do not use PHP Windows installer because it does not support side by side installations.

After a particular version of PHP has been installed in accordance to the instructions, download another version of PHP, extract it into a separate directory and configure it in accordance to Manual Installation Steps. After that proceed to configuring an IIS server as per instructions below:

Note: in all examples below two PHP versions are installed on the same server. PHP 5.2.11 files are located in C:\PHP5211\ directory and PHP 5.3.1 files are located in C:\PHP531\ directory.

IIS 5.1

The FastCGI Extension can be configured on a server and a site level. Since IIS 5.1 can have only one web site, it is not possible to configure it to have two versions of PHP running at the same time. But it is possible to have a configuration that allows to easily switch from one version to another.

Open the IIS FastCGI extension configuration file at %windir%\system32\inetsrv\fcgiext.ini. At the end of the file there will be a section that defines FastCGI applications. It may look similar to this:

[Types]
php=php5211

[php5211]
ExePath=C:\php5211\php-cgi.exe

This configures IIS to use PHP 5.2.11 whenever a request for a *.php file is made. To switch to PHP 5.3.1, just add another section declaration and then modify the [Types] section as below:

[Types]
;php=php5211
php=php531

[php5211]
ExePath=C:\php5211\php-cgi.exe

[php531]
ExePath=C:\php531\php-cgi.exe

To switch back to PHP 5.2.11 update the [Types] section by commenting out php=php531 and un-commenting php=php5211. There is no need to restart IIS after the updates to fcgiexe.ini have been made. FastCGI Extension will pick up the changes as soon as file has been saved.

IIS 6.0

FastCGI on IIS 6.0 can be configured on a server level, which would cause all the IIS web sites to use the same PHP version. Configuring FastCGI on a server level and switching between PHP versions is exactly the same procedure as for IIS 5.1.

Additionally FastCGI can be configured on a site level, which would allow using of different PHP versions for different web sites. To assign a particular PHP version to a site, use the following commands. Make sure to replace the <site_id> with real site identifiers.

cscript %windir%\system32\inetsrv\fcgiconfig.js -add -section:"php5211" ^
-extension:php -path:"C:\php5211\php-cgi.exe" -site:<site_id>

cscript %windir%\system32\inetsrv\fcgiconfig.js -add -section:"php531" ^
-extension:php -path:"C:\php531\php-cgi.exe" -site:<site_id>

After executing these commands open the fcgiext.ini file located in %WINDIR%\system32\inetsrv. It should contain the following sections:

[Types]
php:169297538=php5211 ; The actual site id will be different for your site
php:273357939=php531 ; The actual site id will be different for your site

[php5211]
ExePath=C:\php5211\php-cgi.exe

[php531]
ExePath=C:\php531\php-cgi.exe

IIS 7.0 and later

FastCGI module in IIS 7.0 can be configured on any level: server, site, application and folder. This means that it is even possible to have two applications using different PHP versions within the same web site.

To configure FastCGI on a server level, use these commands:

%windir%\system32\inetsrv\appcmd set config /section:system.webServer/fastCGI ^
/+[fullPath='c:\php531\php-cgi.exe']

%windir%\system32\inetsrv\appcmd set config /section:system.webServer/handlers ^
/+[name='php531', path='*.php',verb='*',modules='FastCgiModule',^
scriptProcessor='c:\php531\php-cgi.exe',resourceType='Either']

Repeat these commands for all the other versions of PHP. By default IIS will use the version that was added last. Now, if you need to use a particular version of PHP for the entire server or for a particular web site, you can just re-order the FastCGI handler mappings for PHP.

Open IIS Manager and use a tree view on left hand side to select a server, site or an application. After that click on “Handler Mappings”:

 IIS Handler Mapping

Then click on “View Ordered List…” action:

 View Ordered List

Select the handler mapping for the PHP version that you want to use for the server or a site and use “Move Up” action to move it to the top of the list. This will enable that particular PHP version for the currently selected IIS configuration scope.

 Reorder Handler Mapping

Note that if you re-order handler mappings on a site or an application level, that site or application will stop inheriting the handler mappings from the upper configuration levels, so the changes to the handler mappings on the server level will not propagate to the site level anymore. To configure a site or an application back to using the inherited handler mappings, use the “Revert To Parent…” action:

Revert To Parent

39,258 views

ruslany on December 16th 2009 in FastCGI, PHP

PoorFairAverageGoodExcellent (4 votes, average: 4.00 out of 5)

9 Responses to “Multiple PHP versions on the same IIS server”

  1. Gravatar ImageMatt Duguid responded on 16 Dec 2009 at 1:09 pm #

    Saw a demo of this at TechEd NZ this year by Jorke Odolphi, very cool. Apparently the speed of PHP on Windows vs Unix is pretty much the same now… ;)

  2. Gravatar ImageSalman responded on 17 Dec 2009 at 3:22 am #

    A side note: if you want the installations to use separate php.ini files as well, modify your fcgiext.ini file as follows:

    [php5211]
    ExePath=C:\php5211\php-cgi.exe
    Arguments=-c C:\php5211\php.ini

    [php531]
    ExePath=C:\php531\php-cgi.exe
    Arguments=-c C:\php531\php.ini

    Another side note: it is possible to have the two separate installations load php shared dlls (not the extensions) from one directory. If this is the case you may try removing PHP path from windows PATH environment variable and add it back to per section environment variables thru fcgiext.ini file.

  3. Gravatar ImageSean responded on 23 Dec 2009 at 1:30 am #

    Very nice guide! I’m impressed with how switching PHP versions on IIS is so easy. Just did it myself in a few minutes.

    The IIS platform is becoming more and more compelling to use with PHP.

  4. Gravatar ImageJames White responded on 04 Jan 2010 at 8:49 am #

    Great guide. Don’t forget to add both PHP directories to the PATH variable and configure each install to point to the correct php.ini.

  5. Gravatar ImageSaqib Ansari responded on 06 Feb 2010 at 4:11 pm #

    5 Wow….

    I really need such guide. I’m going to install PHP different version on my new server but i don’t know how do i install multiple version.

    Thanks

  6. Gravatar ImageBrian Swan responded on 16 Jun 2010 at 4:04 pm #

    I installed PHP 5.2.13 using the Web Platform Installer, then I manually installed PHP 5.3 to run a different website. What I then noticed was that both versions of PHP were loading the same php.ini file. Eventually, I figured out what to do to get each version loading its own php.ini file. (Ruslan very wisely warns about using an installer if you want multiple PHP versions.)

    So, if you installed PHP with the Web Platform Installer (or the Windows installer) and you want a second PHP version that loads its own php.ini file, here’s what to do:

    1. Delete the PHPRC environment variable (Control Panel|System|Advanced Settings). This variable was added by the installer.
    2. Restart your machine.
    3. Manually add/configure a handler for you 2nd PHP version.

    Hope that helps somebody.

    -Brian

  7. Gravatar ImageTasneem responded on 29 May 2012 at 11:00 pm #

    Trying to get this to work on IIS 6, with PHP 5.3,5.2 and 4 TS. Does not seem to work.

  8. Gravatar ImageTasneem responded on 29 May 2012 at 11:02 pm #

    Note I need all 3 of the above to work with their own individual PHP.ini files. Can this be accomplished? One thing I noticed is I’ve set in IIS .php to use C:\apps\php5\php-cgi.exe and not the fcgi dll file.

    Thoughts?

  9. Gravatar ImageGigi Gerow responded on 04 Mar 2014 at 8:27 am #

    Where you say: To configure FastCGI on a server level, use these commands:

    Where do the commands go? Where are they used?
    I understand everything else you’ve said but not the command part.

    Thanks

Trackback URI | Comments RSS

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

XML Markup: If You want to add XML code to the comment please XML encode it first, otherwise the code will not show up.

Recently Published Articles