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

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:

在这里输入图像描述

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:WindowsSystem32inetsrvconfig 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_devbinphp-v5.6php-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.


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.

  • 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%system32inetsrvappcmd.exe unlock config "SiteName/app1" -section:system.webServer/handlers

  • Within the PHP application folder (let's say c:phpapp1) 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:UsersaxputheDocumentsPHPphp-cgi.exe" resourceType="Unspecified" />
            </handlers>
        </system.webServer> 
    </configuration>
    
  • Now if you look at your application within IIS Manager you should see something like this (App Dir -> Handler Mappings)
  • 在这里输入图像描述

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

    链接地址: http://www.djcxy.com/p/38358.html

    上一篇: Spring Framework MVC中的“网页已过期”

    下一篇: 在web.config IIS中配置PHP(或其他)CGI配置