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.
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.
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”:
Then click on “View Ordered List…” action:
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.
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: