Php

使用 PowerShell 創建 FastCGI 應用程序

  • August 22, 2017

我正在嘗試自動配置 Windows 2012 伺服器,但我無法讓 PHP 正常工作。

這是我用來向 IIS 添加處理程序映射的命令:

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

這正確地添加了處理程序映射,到目前為止一切都很好。

但是,我仍然需要為執行檔手動創建一個 FastCGI 應用程序才能使其工作。自動執行此操作的 PowerShell 命令是什麼?我找不到任何指向正確方向的東西。

我正在解決同樣的問題。此腳本將更新您的 apphost 配置以創建 FastCGI 程序池和處理程序映射。

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 }

引用自:https://serverfault.com/questions/807181