Criar aplicativo FastCGI com o PowerShell

4

Estou tentando automatizar o provisionamento de um servidor Windows 2012, mas estou tendo problemas para fazer o PHP funcionar.

Este é o comando que estou usando para adicionar um mapeamento de manipulador ao IIS:

New-WebHandler -Name "PHP-FastCGI" -Path "*.php" -Verb "*" -Modules "FastCgiModule" -ScriptProcessor "c:\php\php-cgi.exe" -ResourceType File

Isso adiciona corretamente o mapeamento do manipulador, até aí tudo bem.

No entanto, ainda preciso criar manualmente um aplicativo FastCGI para que o executável funcione. Qual é o comando do PowerShell para automatizar isso? Não consigo encontrar nada que me aponte na direção certa.

    
por Willem-Aart 05.10.2016 / 11:00

1 resposta

5

Eu estava trabalhando no mesmo problema. Esse script atualizará sua configuração do apphost para criar o pool de processos FastCGI e o mapeamento do manipulador.

import-module WebAdministration

###############################################################
# Adds a FastCGI process pool in IIS
###############################################################
$php = 'C:\php\php-cgi.exe'
$configPath = get-webconfiguration 'system.webServer/fastcgi/application' | where-object { $_.fullPath -eq $php }
if (!$configPath) {
    add-webconfiguration 'system.webserver/fastcgi' -value @{'fullPath' = $php }
}

###############################################################
# Create IIS handler mapping for handling PHP requests
###############################################################
$handlerName = "PHP 7.0.12"
$handler = get-webconfiguration 'system.webserver/handlers/add' | where-object { $_.Name -eq $handlerName }
if (!$handler) {
    add-webconfiguration 'system.webServer/handlers' -Value @{
        Name = $handlerName;
        Path = "*.php";
        Verb = "*";
        Modules = "FastCgiModule";
        scriptProcessor=$php;
        resourceType='Either' 
    }
}

###############################################################
# Configure the FastCGI Setting
###############################################################
# Set the max request environment variable for PHP
$configPath = "system.webServer/fastCgi/application[@fullPath='$php']/environmentVariables/environmentVariable"
$config = Get-WebConfiguration $configPath
if (!$config) {
    $configPath = "system.webServer/fastCgi/application[@fullPath='$php']/environmentVariables"
    Add-WebConfiguration $configPath -Value @{ 'Name' = 'PHP_FCGI_MAX_REQUESTS'; Value = 10050 }
}

# Configure the settings
# Available settings: 
#     instanceMaxRequests, monitorChangesTo, stderrMode, signalBeforeTerminateSeconds
#     activityTimeout, requestTimeout, queueLength, rapidFailsPerMinute, 
#     flushNamedPipe, protocol   
$configPath = "system.webServer/fastCgi/application[@fullPath='$php']"
Set-WebConfigurationProperty $configPath -Name instanceMaxRequests -Value 10000
Set-WebConfigurationProperty $configPath -Name monitorChangesTo -Value 'C:\php\php.ini'

# Restart IIS to load new configs.
invoke-command -scriptblock {iisreset /restart }
    
por 31.10.2016 / 21:21