Search code examples
phpwebmatrixiis-express

How do you configure WebMatrix to run PHP on *.htm, *.html files?


I'm running a PHP website locally using WebMatrix. This site uses PHP within *.html files. By default, WebMatrix doesn't allow this. How do I configure WebMatrix so that the PHP runs?

(note that I'm answering my own question)


Solution

  • You need to edit the file:

    %USERPROFILE%\Documents\IISExpress\config\applicationhost.config
    

    (For example, "C:\Users\Marcus\Documents\IISExpress\config\applicationhost.config")

    You'll notice a line like this:

    <add name="PHP53_via_FastCGI" path="*.php" verb="GET,HEAD,POST" modules="FastCgiModule" scriptProcessor="C:\Program Files (x86)\iis express\PHP\v5.3\php-cgi.exe" resourceType="Either" />
    

    You can add other file extensions by adding new lines:

    <add name="PHP53_via_FastCGI_html" path="*.html" verb="GET,HEAD,POST" modules="FastCgiModule" scriptProcessor="C:\Program Files (x86)\iis express\PHP\v5.3\php-cgi.exe" resourceType="Either" />
    <add name="PHP53_via_FastCGI_htm" path="*.htm" verb="GET,HEAD,POST" modules="FastCgiModule" scriptProcessor="C:\Program Files (x86)\iis express\PHP\v5.3\php-cgi.exe" resourceType="Either" />
    

    It's important that you give each <add /> element a unique 'name' attribute.