php配置模块映射,PHP模块中使用appcmd.exe添加FastCGI映射的方法

配置示例

以下示例包含两个定义处理程序映射的元素。第一个元素为在IIS 7集成模式下运行的Web应用程序定义SampleHandler处理程序。如果将处理程序程序集添加到Web应用程序的app_code目录中,则不需要在type属性的值中包含程序集名称。第二个元素定义了使用FastCGI模块的PHP请求的映射。

path="SampleHandler.new"

type="SampleHandler, SampleHandlerAssembly"

resourceType="Unspecified" />

path="*.php"

modules="FastCgiModule"

scriptProcessor="c:\php\php-cgi.exe"

resourceType="Either" />

示例代码

以下示例为PHP模块添加FastCGI映射,然后在Contoso Web站点上添加将处理PHP请求的处理程序。

Appcmd.exe的appcmd.exe set config -section:system.webServer/fastCgi /+"[fullPath='c:\php\php-cgi.exe']" /commit:apphostappcmd.exe set config "Contoso" -section:system.webServer/handlers /+"[name='PHP-FastCGI',path='*.php',verb='GET,HEAD,POST',modules='FastCgiModule',scriptProcessor='c:\php\php-cgi.exe',resourceType='Either']"

注意

第二个示例显示如何将特定URL的名为SampleHandler.new的新ASP.NET处理程序映射添加到Web应用程序。appcmd.exe set config /section:system.webServer/handlers /+[name=SampleHandler',path='SampleHandler.new',verb='*',type='SampleHandler']

C#using System;using System.Text;using Microsoft.Web.Administration;internal static class Sample{

private static void Main()

{

using (ServerManager serverManager = new ServerManager())

{

Configuration appHostConfig = serverManager.GetApplicationHostConfiguration();

ConfigurationSection fastCgiSection = appHostConfig.GetSection("system.webServer/fastCgi");

ConfigurationElementCollection fastCgiCollection = fastCgiSection.GetCollection();

ConfigurationElement applicationElement = fastCgiCollection.CreateElement("application");

applicationElement["fullPath"] = @"c:\php\php-cgi.exe";

fastCgiCollection.Add(applicationElement);

Configuration webConfig = serverManager.GetWebConfiguration("Contoso");

ConfigurationSection handlersSection = webConfig.GetSection("system.webServer/handlers");

ConfigurationElementCollection handlersCollection = handlersSection.GetCollection();

ConfigurationElement addElement = handlersCollection.CreateElement("add");

addElement["name"] = @"PHP-FastCGI";

addElement["path"] = @"*.php";

addElement["verb"] = @"GET,HEAD,POST";

addElement["modules"] = @"FastCgiModule";

addElement["scriptProcessor"] = @"c:\php\php-cgi.exe";

addElement["resourceType"] = @"Either";

handlersCollection.AddAt(0, addElement);

serverManager.CommitChanges();

}

}}

VB.NETImports SystemImports System.TextImports Microsoft.Web.AdministrationModule Sample

Sub Main()

Dim serverManager As ServerManager = New ServerManager

Dim appHostConfig As Configuration = serverManager.GetApplicationHostConfiguration

Dim fastCgiSection As ConfigurationSection = appHostConfig.GetSection("system.webServer/fastCgi")

Dim fastCgiCollection As ConfigurationElementCollection = fastCgiSection.GetCollection

Dim applicationElement As ConfigurationElement = fastCgiCollection.CreateElement("application")

applicationElement("fullPath") = "c:\php\php-cgi.exe"

fastCgiCollection.Add(applicationElement)

Dim webConfig As Configuration = serverManager.GetWebConfiguration("Contoso")

Dim handlersSection As ConfigurationSection = webConfig.GetSection("system.webServer/handlers")

Dim handlersCollection As ConfigurationElementCollection = handlersSection.GetCollection

Dim addElement As ConfigurationElement = handlersCollection.CreateElement("add")

addElement("name") = "PHP-FastCGI"

addElement("path") = "*.php"

addElement("verb") = "GET,HEAD,POST"

addElement("modules") = "FastCgiModule"

addElement("scriptProcessor") = "c:\php\php-cgi.exe"

addElement("resourceType") = "Either"

handlersCollection.AddAt(0, addElement)

serverManager.CommitChanges()

End SubEnd Module

JavaScript的var adminManager = new ActiveXObject('Microsoft.ApplicationHost.WritableAdminManager');adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST";var fastCgiSection = adminManager.GetAdminSection("system.webServer/fastCgi", "MACHINE/WEBROOT/APPHOST");var fastCgiCollection = fastCgiSection.Collection;var applicationElement = fastCgiCollection.CreateNewElement("application");applicationElement.Properties.Item("fullPath").Value = "c:\\php\\php-cgi.exe";fastCgiCollection.AddElement(applicationElement);adminManager.CommitChanges();adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST/Contoso";var handlersSection = adminManager.GetAdminSection("system.webServer/handlers", "MACHINE/WEBROOT/APPHOST/Contoso");var handlersCollection = handlersSection.Collection;var addElement = handlersCollection.CreateNewElement("add");addElement.Properties.Item("name").Value = "PHP-FastCGI";addElement.Properties.Item("path").Value = "*.php";addElement.Properties.Item("verb").Value = "GET,HEAD,POST";addElement.Properties.Item("modules").Value = "FastCgiModule";addElement.Properties.Item("scriptProcessor").Value = "c:\\php\\php-cgi.exe";addElement.Properties.Item("resourceType").Value = "Either";handlersCollection.AddElement(addElement, 0);adminManager.CommitChanges();

VBScript中Set adminManager = createObject("Microsoft.ApplicationHost.WritableAdminManager")adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST"Set fastCgiSection = adminManager.GetAdminSection("system.webServer/fastCgi", "MACHINE/WEBROOT/APPHOST")Set fastCgiCollection = fastCgiSection.CollectionSet applicationElement = fastCgiCollection.CreateNewElement("application")applicationElement.Properties.Item("fullPath").Value = "c:\php\php-cgi.exe"fastCgiCollection.AddElement applicationElementadminManager.CommitChanges()adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST/Contoso"Set handlersSection = adminManager.GetAdminSection("system.webServer/handlers", "MACHINE/WEBROOT/APPHOST/Contoso")Set handlersCollection = handlersSection.CollectionSet addElement = handlersCollection.CreateNewElement("add")addElement.Properties.Item("name").Value = "PHP-FastCGI"addElement.Properties.Item("path").Value = "*.php"addElement.Properties.Item("verb").Value = "GET,HEAD,POST"addElement.Properties.Item("modules").Value = "FastCgiModule"addElement.Properties.Item("scriptProcessor").Value = "c:\php\php-cgi.exe"addElement.Properties.Item("resourceType").Value = "Either"handlersCollection.AddElement addElement, 0adminManager.CommitChanges()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值