加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – 使用PowerShell创建FastCGI应用程序

发布时间:2020-12-13 13:54:24 所属栏目:PHP教程 来源:网络整理
导读:我正在尝试自动配置 Windows 2012服务器,但我无法让 PHP工作. 这是我用来添加处理程序映射到IIS的命令: New-WebHandler -Name "PHP-FastCGI" -Path "*.php" -Verb "*" -Modules "FastCgiModule" -ScriptProcessor "c:phpphp-cgi.exe" -ResourceType File
我正在尝试自动配置 Windows 2012服务器,但我无法让 PHP工作.

这是我用来添加处理程序映射到IIS的命令:

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

这正确地添加了处理程序映射,到目前为止一直很好.

但是,我仍然需要为可执行文件手动创建FastCGI应用程序以使其工作.什么是PowerShell命令来自动执行此操作?我找不到任何指向正确方向的东西.

我正在研究同样的问题.此脚本将更新您的apphost配置以创建FastCGI进程池和处理程序映射.
import-module WebAdministration

###############################################################
# Adds a FastCGI process pool in IIS
###############################################################
$php = 'C:phpphp-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:phpphp.ini'

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读