0

I am trying to automatically deploy an IIS webserver (currently 8.5, will need to work it out all the way down to 7.5 as well), using AppCmd.exe

I am using PHP's FastCGI to handle requests. I have configured the FastCGI pool on server level.

Now I need to set up a new handler to handle *.php requests with the FastCGI module.

The PHP documentation and various Microsoft docs say that this AppCmd command will do it:

%windir%\system32\inetsrv\appcmd set config /section:system.webServer/handlers /+ [name='PHP_via_FastCGI',path='.php',verb='',modules='FastCgiModule',scriptProcessor='c:\PHP\php-cgi.exe',resourceType='Either']

source: http://php.net/manual/de/install.windows.iis7.php

While this does in fact work, it puts the handler on server level as well. I need the handler to be on website level though.

I have tried various combinations, finally coming up with the following command:

set config "Default Web Site/" -section:system.webServer/handlers /+[name='PHP_via_FastCGI',path='.php',verb='',modules='FastCgiModule',scriptProcessor='c:\PHP\php-cgi.exe',resourceType='Either']

Which tells me that the configuration cannot be done on this level.

However when I am using the UI to add the handler to the website, I can do it with no problems. Thus I think my command is still wrong.

What am I doing wrong here?

Cheers and thx a lot, Worp

Worp
  • 287
  • 1
  • 4
  • 15

1 Answers1

1

Try this one:

appcmd.exe set config "Default Web Site" -section:system.webServer/handlers /+"[name='PHP_via_FastCGI',path='*.php',verb='',modules='FastCgiModule',scriptProcessor='c:\PHP\php-cgi.exe',resourceType='Either']" /commit:apphost

It still changes ApplicationHost.config rather than web.config but only applies to one site.

Peter Hahndorf
  • 13,763
  • 3
  • 37
  • 58
  • Ahhh....the commit at the end. I get it. I will try that and report back. – Worp Jan 30 '15 at 10:05
  • So I played around with it a bit and it's not quite what I want. – Worp Jan 30 '15 at 13:46
  • Waited to long to edit the comment above, so here is the rest: So I played around with it a bit and it's not quite what I want. Executing the command with /commit:apphost does the same thing as executing without it. Both times the handler can be found on server level. It is marked as "local" in both the server and the site level. But it's still there. I need it to actually not be applied to the serverlevel. Sadly this is not a solution. – Worp Jan 30 '15 at 13:51
  • @Worp - I just tried this command on a fresh Server, it only added a node for the site, not for the server. Are you sure you didn't already have a server entry before? – Peter Hahndorf Jan 30 '15 at 14:44
  • As I had put in my comment and sent it, I went down to the applicationHost.config and deleted the lines specifying any PHP Handlers in there manually. After doing that, I used your line again and it worked. I had tried deleting any existing PHP Handlers via the UI before but that would still only give me a server-level handler. Now it does set up on site level only just fine. I am sorry, I am not sure where I went wrong. I correct myself: This answer does solve it. Many regards! – Worp Jan 30 '15 at 15:01
  • Ah, I forgot a tiny thing: Can you edit your answer from "path='.php'" to "path='*.php'" (The little asteriks). Otherwise users directly copying the line still get a 404.3. – Worp Jan 30 '15 at 15:15