Enabling PHP on IIS Express with Visual Studio (sans WebMatrix) Enabling PHP on IIS Express with Visual Studio (sans WebMatrix) php php

Enabling PHP on IIS Express with Visual Studio (sans WebMatrix)


IIS Express supports PHP without Web matrix. You can install just IIS Express alone and make it work with Visual Studio. For this you need Visual Studio 2010 SP1.

  1. Download IIS Express from this link: Internet Information Services (IIS) 7.5 Express

  2. In Visual Studio configure your WebSite/WebApplication project to use IIS Express. Take a look at this thread How do I configure a website project to use IIS Express?

  3. To enable PHP on IIS Express, install PHP and update applicationhost.config (%userprofile%\documents\iisexpress\config\applicationhost.config). You can use the version of appcmd.exe located in IIS Express installation folder for doing this. See this link for details.

If everything is installed in the default places for US English versions of Windows the commands will be:

"C:\Program Files (x86)\IIS Express\appcmd.exe" set config /section:system.webServer/fastCGI /+[fullPath='"C:\Program Files (x86)\PHP\php-cgi.exe"']"C:\Program Files (x86)\IIS Express\appcmd.exe" set config /section:system.webServer/handlers /+[name='PHP_via_FastCGI',path='*.php',verb='*',modules='FastCgiModule',scriptProcessor='"C:\Program Files (x86)\PHP\php-cgi.exe"',resourceType='Unspecified']

Note that if there are spaces in the full path of php-cgi.exe, you MUST enclose the path in single and double quotes as in the example above.

Finally, if you don't have VS 2010 SP1, probably you should take a look at this post: Debug Your .NET Web Project With IIS Express


Another option is to use Web Platform Installer.

Web Platform Installer will install PHP and configure IIS Express for you.


Newer versions of Visual Studio maintain a separate copy of IIS Express's configuration file "applicationhost.config". Most of the instructions online show you how to target the master applicationhost.config file which has no effect because VS2017 maintains a separate copy and uses this copy when starting IIS express. To enable PHP in this scenario, I had to edit VS2017's private copy.

  • Prerequisite - Use the web platform installer to install PHP. (You don't need the one for IIS Express, just the regular PHP download.) You can use x86 or x64. This will install PHP into either C:\Program Files\ or C:\Program Files (x86)\ depending on which one you choose. You could also simply grab PHP from their website.

  • Locate your project's applicationhost.config. It is located in a hidden .vs subfolder. For example C:\MyProject\.vs\applicationhost.config

  • Run the following commands from a command window, substituting your paths for the project folder and the PHP binaries you installed.

"C:\Program Files (x86)\IIS Express\appcmd.exe" set config /section:system.webServer/fastCGI /+[fullPath='"C:\Program Files (x86)\PHP\{{YOUR PHP VERSION}}\php-cgi.exe"'] /apphostconfig:"C:\{{YOUR PROJECT}}\.vs\config\applicationhost.config""C:\Program Files (x86)\IIS Express\appcmd.exe" set config /section:system.webServer/handlers /+[name='PHP_via_FastCGI',path='*.php',verb='*',modules='FastCgiModule',scriptProcessor='"C:\Program Files (x86)\PHP\{{YOUR PHP VERSION}}\php-cgi.exe"',resourceType='Unspecified'] /apphostconfig:"C:\{{YOUR PROJECT}}\.vs\config\applicationhost.config"

Alternatively, you can simply edit the project's applicationhost.config in a text editor and add the following sections.

system.webServer/fastCGI

<fastCgi>    <application fullPath="C:\Program Files (x86)\PHP\v7.1\php-cgi.exe" /></fastCgi>

system.webServer/handlers

<add name="PHP_via_FastCGI" path="*.php" verb="*" modules="FastCgiModule" scriptProcessor="C:\Program Files (x86)\PHP\v7.1\php-cgi.exe" resourceType="Unspecified" />

To be clear, editing the IIS Express\AppServer\applicationhost.config or the one in your %appdata% folder will not help unless you're doing something advanced like starting IIS Express outside Visual Studio.