Home » Php » PHP (or whatever) CGI configuration in web.config IIS

PHP (or whatever) CGI configuration in web.config IIS

Posted by: admin July 12, 2020 Leave a comment

Questions:

I recently developed an installer for a web application (Yes, Web Application with an Installer) using Wix Tool Set.

The wizard guides the user to obtain all the basic information the site need for the installation, and looks like below:

enter image description here

Using custom actions at the end of the installation I configured dynamically the IIS to handler CGI using the documentation, to configure FastCGI to Host PHP, Python, Applications. There are a lot of steps and development to achieve this results, but the problem is here:

I installed the application and everything works fine, but, if I uninstall or install another Instance or another WebApplication the handlers configure by IIS is like globally and always points to the first installed. (The problem occurs when I uninstall the application)
The applicationHost.config located in C:\Windows\System32\inetsrv\config that is the configuration of IIS has the “config” like global.

<handlers accessPolicy="Read, Script">
            <add name="PHP-FastCGI" path="*.php" verb="*" modules="FastCgiModule" scriptProcessor="E:\CIM_dev\bin\php-v5.6\php-cgi.exe" resourceType="Either" />
            <add name="CGI-exe_2" path="*.exe" verb="*" modules="CgiModule" resourceType="File" requireAccess="Execute" allowPathInfo="true" />
            <add name="TRACEVerbHandler2" path="*" verb="TRACE" modules="ProtocolSupportModule" requireAccess="None" />
            <add name="OPTIONSVerbHandler2" path="*" verb="OPTIONS" modules="ProtocolSupportModule" requireAccess="None" />
            <add name="StaticFile2" path="*" verb="*" modules="StaticFileModule,DefaultDocumentModule,DirectoryListingModule" resourceType="Either" requireAccess="Read" />
        </handlers>

My question is, is there any way to do this configuration for each web site into the web.config? I’ve been trying all stuff without success.

How to&Answers:

So if I understand it right, you want to move php handlers from server/website level to individual applications. Why dont you add a web.config file within your php application folder and move the application specific handlers there.

  1. https://stackoverflow.com/a/35332431/1766402 – check this answer (I am hoping you have CGI enabled in IIS?). To do this via wix, can you add the following command within a custom action and execute. This will unlock the parent config file.

%windir%\system32\inetsrv\appcmd.exe unlock config “SiteName/app1”
-section:system.webServer/handlers

  1. Within the PHP application folder (let’s say c:\php\app1) create a web.config file with the following content:
<?xml version="1.0"?>
<configuration>
    <system.webServer>      
        <handlers>
            <add name="PHPviaFastCGI" path="*.php" verb="*" modules="FastCgiModule" scriptProcessor="C:\Users\axputhe\Documents\PHP\php-cgi.exe" resourceType="Unspecified" />
        </handlers>
    </system.webServer> 
</configuration>
  1. Now if you look at your application within IIS Manager you should see something like this (App Dir -> Handler Mappings)

enter image description here

Note “local” this confirms that the setting is coming from your local web.config and not from the applicationhost.config file.