powershell执行php,php – 使用PowerShell创建FastCGI应用程序

搜索热词

我正在尝试自动配置

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 }

总结

如果觉得编程之家网站内容还不错,欢迎将编程之家网站推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值