• Windows2003上使用IIS7 Express使用FastCgi运行php


         先说一下背景,因为是自己租来的VPS管理代码、文档及跑一些自己用的一些服务程序,为了便宜又稳定就考虑租了台windows2003的vps,内存总共只1G,很捉襟见肘。

         在Web服务这一块,同一台装了2003的服务器上,需要跑PHP及ASP.NET,IIS6上安装了PHP后,加装Rewrite组件,可以较正常的跑wordpress,但后来由于rewrite组件过期了,去网上找了各种版本的安装,仍然无用,总是提示已过期。

         于是只好考虑用用nginx做的反向代理,动态解析转向到IIS6及Apache上,但这样整体内存占用看起来有点大,于是停用了Apache,转而用nginx加PHP-cgi.exe来跑wordpress,发现访问速度似乎提升了一些,但是php进程动不动就自动退出,于是又写个管理php-cgi.exe的守护进程。后来,nginx又不正常了,时不时出点小毛病,而php-cgi用守护进程只启动一个进程,也时常出问题,如果启动一堆的话,加上守护进程与php-cgi所占用的内存,还不如直接nginx转apache算了。

         总之,确定在windows下,想好好跑php,又要节省内存,真的不容易。

         然后考虑到IIS7.5 Express可以在WIN2003上跑,不但能以fastcgi的方式支持php,还自带Rewrite组件,只需简单改改web.config的rule规则就可以了。

         于是百度下载了IIS7.5 Express后,安装,还需要对applicationHost.config进行配置,首先得找到这个文件在哪里,如果能在"我的文档"中IIS7Express目录下找到,那就是它了,否则应该就是在IIS7 Express的安装目录下。

         1、先修改:defaultDocument节,加入 <add value="index.php" />

    <defaultDocument enabled="true">
                <files>
                    <add value="Default.htm" />
                    <add value="Default.asp" />
                    <add value="index.htm" />
                    <add value="index.html" />
                    <add value="iisstart.htm" />
                    <add value="default.aspx" />
                    <add value="index.php" />
                </files>
    </defaultDocument>
    

         2、找到fastcgi节。

    <fastCgi>
                <application fullPath="C:\php\php-cgi.exe" monitorChangesTo="php.ini" activityTimeout="600" requestTimeout="600" instanceMaxRequests="10000">
                    <environmentVariables>
                        <environmentVariable name="PHP_FCGI_MAX_REQUESTS" value="10000" />
                        <environmentVariable name="PHPRC" value="C:Program Files (x86)iis expressPHPv5.4" />
                    </environmentVariables>
                </application>
    </fastCgi>
    

       3、找到handlles,加入

     <add name="PHP_FastCGI" path="*.php" verb="GET,HEAD,POST" modules="FastCgiModule" scriptProcessor="C:\PHP\php-cgi.exe" resourceType="Either" />
    

        尤其要注意的一是,这一句最好加在最前面,也就是在<handlles>下面的第一句,避免被其它Handle抢先处理了。

        以上配置中,C:\php\php-cgi.exe 的部分替换成自己的php文件夹中的php-cgi.exe的位置。

      4、在<site>配置节下,直接修改站点信息,或直接用appcmd.exe add site来添加站点。

      5、找到诸如wordpress的安装文件夹,创建一个web.config文件,在configuration配置节下,添加Gzip压缩规则。

    <system.webServer>
       <urlCompression doStaticCompression="true" doDynamicCompression="true" />
    </system.webServer>
    

     6、同样在web.config中,Wordpress的rewrite完整的web.config文件内容如下:

    <configuration>
      <system.webServer>
        <rewrite>
          <rules>
            <rule name="wordpress" patternSyntax="Wildcard">
              <match url="*" />
                <conditions>
                  <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                  <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                </conditions>
              <action type="Rewrite" url="index.php" />
            </rule>
          </rules>
        </rewrite>
      </system.webServer>
    <system.webServer>
       <urlCompression doStaticCompression="true" doDynamicCompression="true" />
    </system.webServer>
    </configuration>
    

     这样就完全配置完毕了,然后在IIS7 Express目录下,找到IISExpress.exe,直接双击运行,或者用命令行来执行指定加载哪个站点. 

    iisexpress.exe /site:'站点名称1"
    iisexpress.exe /site:'站点名称2"
    

     访问一下,就会发现访问速度比在windows下使用apache要快得多,而且少跑一个nginx,内存占用整体上也少了很多。

  • 相关阅读:
    appium===报错Failure [INSTALL_FAILED_ALREADY_EXISTS: Attempt to re-install io.appium.settings without first uninstalling.的解决办法
    Appium===Appium+Python API(转)
    appium===出错时截图的方法,自动截图
    appium===setup/setupclass的区别,以及@classmathod的使用方法
    appium===元素定位
    appium===Python+Appium环境部署教程
    appium===报错adb server version (31) doesn’t match this client (39); killing…的解决办法
    appium===安卓SDK下载很慢的解决办法
    HTTP===通用首部字段的各种指令解释
    HTTP===http首部字段
  • 原文地址:https://www.cnblogs.com/William_Fire/p/3101374.html
Copyright © 2020-2023  润新知