您现在的位置: 365建站网 > 365文章 > PHP模块中使用appcmd.exe添加FastCGI映射的方法

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

文章来源:365jz.com     点击数:733    更新时间:2018-07-31 14:08   参与评论

配置示例

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

</>code

  1. <handlers>
  2.    <add name="SampleHandler" verb="*" 
  3.       path="SampleHandler.new" 
  4.       type="SampleHandler, SampleHandlerAssembly" 
  5.       resourceType="Unspecified" />
  6.    <add name="PHP-FastCGI" verb="*" 
  7.       path="*.php" 
  8.       modules="FastCgiModule"
  9.       scriptProcessor="c:\php\php-cgi.exe" 
  10.       resourceType="Either" /></handlers>

示例代码

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

Appcmd.exe的

</>code

  1. 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应用程序。

</>code

  1. appcmd.exe set config /section:system.webServer/handlers /+[name=SampleHandler',path='SampleHandler.new',verb='*',type='SampleHandler']

C#

</>code

  1. using System;using System.Text;using Microsoft.Web.Administration;internal static class Sample{
  2.    private static void Main()
  3.    {
  4.       using (ServerManager serverManager = new ServerManager())
  5.       {
  6.          Configuration appHostConfig = serverManager.GetApplicationHostConfiguration();
  7.          ConfigurationSection fastCgiSection = appHostConfig.GetSection("system.webServer/fastCgi");
  8.          ConfigurationElementCollection fastCgiCollection = fastCgiSection.GetCollection();
  9.          ConfigurationElement applicationElement = fastCgiCollection.CreateElement("application");
  10.          applicationElement["fullPath"] = @"c:\php\php-cgi.exe";
  11.          fastCgiCollection.Add(applicationElement);
  12.          Configuration webConfig = serverManager.GetWebConfiguration("Contoso");
  13.          ConfigurationSection handlersSection = webConfig.GetSection("system.webServer/handlers");
  14.          ConfigurationElementCollection handlersCollection = handlersSection.GetCollection();
  15.          ConfigurationElement addElement = handlersCollection.CreateElement("add");
  16.          addElement["name"] = @"PHP-FastCGI";
  17.          addElement["path"] = @"*.php";
  18.          addElement["verb"] = @"GET,HEAD,POST";
  19.          addElement["modules"] = @"FastCgiModule";
  20.          addElement["scriptProcessor"] = @"c:\php\php-cgi.exe";
  21.          addElement["resourceType"] = @"Either";
  22.          handlersCollection.AddAt(0, addElement);
  23.          serverManager.CommitChanges();
  24.       }
  25.    }}

VB.NET

</>code

  1. Imports SystemImports System.TextImports Microsoft.Web.AdministrationModule Sample
  2.    Sub Main()
  3.       Dim serverManager As ServerManager = New ServerManager
  4.       Dim appHostConfig As Configuration = serverManager.GetApplicationHostConfiguration
  5.       Dim fastCgiSection As ConfigurationSection = appHostConfig.GetSection("system.webServer/fastCgi")
  6.       Dim fastCgiCollection As ConfigurationElementCollection = fastCgiSection.GetCollection
  7.       Dim applicationElement As ConfigurationElement = fastCgiCollection.CreateElement("application")
  8.       applicationElement("fullPath") = "c:\php\php-cgi.exe"
  9.       fastCgiCollection.Add(applicationElement)
  10.       Dim webConfig As Configuration = serverManager.GetWebConfiguration("Contoso")
  11.       Dim handlersSection As ConfigurationSection = webConfig.GetSection("system.webServer/handlers")
  12.       Dim handlersCollection As ConfigurationElementCollection = handlersSection.GetCollection
  13.       Dim addElement As ConfigurationElement = handlersCollection.CreateElement("add")
  14.       addElement("name") = "PHP-FastCGI"
  15.       addElement("path") = "*.php"
  16.       addElement("verb") = "GET,HEAD,POST"
  17.       addElement("modules") = "FastCgiModule"
  18.       addElement("scriptProcessor") = "c:\php\php-cgi.exe"
  19.       addElement("resourceType") = "Either"
  20.       handlersCollection.AddAt(0, addElement)
  21.       serverManager.CommitChanges()
  22.    End SubEnd Module

JavaScript的

</>code

  1. 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中

</>code

  1. 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()


如对本文有疑问,请提交到交流论坛,广大热心网友会为你解答!! 点击进入论坛

发表评论 (733人查看0条评论)
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
昵称:
最新评论
------分隔线----------------------------

快速入口

· 365软件
· 杰创官网
· 建站工具
· 网站大全

其它栏目

· 建站教程
· 365学习

业务咨询

· 技术支持
· 服务时间:9:00-18:00
365建站网二维码

Powered by 365建站网 RSS地图 HTML地图

copyright © 2013-2024 版权所有 鄂ICP备17013400号