xibeimu 发表于 2011-10-29 10:11:12

windows 2008 R2 下 IIS7.5+PHP+Mysql+Zend完美运行fastcgi

               
windows 2008 R2 下面IIS7.5已经对fastcg的支持有了很大改进,我们不建议朋友们再使用PHP-ISAPi模式。
本次环境搭建所有版本均经过多次测试保证无误!鉴于目前php5.3.1还不能完美的支持主流php系统,不建议大家使用!
windows2008 R2下面环境搭建分三种情况 大家可以根据自己的运行需要选择!
1 IIS7.5+PHP+Mysql+Wincache 1.0RC
这个环境组合大家已经看出来了 没有zend,
各个版本分别是:
PHP5.2.11--请注意是非线程安全版本 PHP 5.2.11 Non-thread-safe zip package,
MYSQL5.0 x64,
Wincache1.0rc for5.2,这个大家可以去微软IIS官方下载,他将极大地提高您的系统运行效率!
如果您的服务器运行的都是开源程序,不需要zend,强烈建议您使用这个配置!

2 IIS7.5+PHP+Mysql+Zend+Xcache
此组合版本分别是
PHP5.2.11 请注意是线程安全版本:PHP 5.2.11 zip package
MYSQL5.0 x64,
ZendOptimizer3.3.3-windows x86
Xcache1.3 for XCache-1.3.0-php-5.2.10-Win32-VC6-x86.zip
此组合可以完美运行当今主流的PHP系统,但是美中不足的是使用PHP线程安全版本无法加载wincache,很遗憾的一点!但是可以用xcache作为补充,但是相比PHP-ISAPI模式已经好多了!

3 鉴于IIS7.5的新特性,我们可以根据每个站点的具体情况定制属于他的专有运行环境!
在iis7.5 fastcgi模式下,IIS官方建议为每个站点设立单独的应用池,并且每个站点都可以拥有它自己的PHP.ini以及fastcgi.exe.允许在一台主机上运行不同版本的PHP.
官方是这样描述的:Enabling per-site PHP configuration
The section describes the recommended way of enabling per-site PHP configuration . Note that this recommendation was discovered and validated by Radney Jasmin with hosting provider GoDaddy.com who now offers PHP hosting on Windows Server 2008 via FastCGI.Per-site PHP process pools
When each web site has its own application pool (which is a recommended practice on IIS 7.0), it is possible to associate a dedicated FastCGI process pool with each web site. A FastCGI process pool is uniquely identified by the combination of fullPath and arguments attributes. So, if it is necessary to create several FastCGI process pools for the same process executable, such as php-cgi.exe, the arguments attribute can be used to distinguish process pools definitions. In addition, with php-cgi.exe processes the command line switch "-d" can be used to define an INI entry for PHP process. This switch can be used to set a PHP setting that makes the arguments string unique.
For example, if there are two web sites "website1" and "website2" that need to have their own set of PHP settings, the FastCGI process pools can be defined as follows:
<fastCgi>
    <application fullPath="C:\PHP\php-cgi.exe" arguments="-d open_basedir=C:\Websites\Website1" />
    <application fullPath="C:\PHP\php-cgi.exe" arguments="-d open_basedir=C:\Websites\Website2" />
</fastCgi>
In this example the PHP setting open_basedir is used to distinguish between process pool definitions. In addition it enforces that the PHP executable for each process pool can perform file operations only within the root folder of the corresponding web site.
Then website1 can have the PHP handler mapping as follows:
<system.webServer>
    <handlers accessPolicy="Read, Script">
      <add name="PHP via FastCGI" path="*.php" verb="*" modules="FastCgiModule" scriptProcessor="C:\PHP\php-cgi.exe|-d open_basedir=C:\Websites\Website1" resourceType="Unspecified" requireAccess="Script" />
    </handlers>
</system.webServer>
and website2 can have the PHP handler mapping as follows:
<system.webServer>
    <handlers accessPolicy="Read, Script">
      <add name="PHP via FastCGI" path="*.php" verb="*" modules="FastCgiModule" scriptProcessor="C:\PHP\php-cgi.exe|-d open_basedir=C:\Websites\Website2" resourceType="Unspecified" requireAccess="Script" />
    </handlers>
</system.webServer> Specifying php.ini location
When the PHP process starts it determines the location of the configuration php.ini file by using various settings. The PHP documentation provides detailed description of the PHP start up process. Note that one of the places where PHP process searches for php.ini location is the PHPRC environment variable. If PHP process finds a php.ini file in the path specified in this environment variable then it will use it, otherwise it will revert to default location of php.ini. This environment variable can be used to allow hosting customers to use their own versions of php.ini files.
For example if there are two websites: website1 and website2; located at the following file paths: C:\WebSites\website1 and C:\WebSites\website2 then the php-cgi.exe process pools in the <fastCgi> section of applicationHost.config can be configured as below:
<fastCgi>
    <application fullPath="C:\PHP\php-cgi.exe" arguments="-d open_basedir=C:\Websites\Website1">
      <environmentVariables>
            <environmentVariable name="PHPRC" value="C:\WebSites\website1" />
      </environmentVariables>
    </application>
    <application fullPath="C:\PHP\php-cgi.exe" arguments="-d open_basedir=C:\WebSites\Website2">
      <environmentVariables>
            <environmentVariable name="PHPRC" value="C:\WebSites\website2" />
      </environmentVariables>
    </application>
</fastCgi>
This way website1 can have its own version of php.ini in the C:\WebSites\website1, while website2 can have its own version of php.ini located in C:\WebSites\website2. This configuration also ensures that if there is no php.ini found in location specified by PHPRC environment variable then PHP will fall back to using the default php.ini file located in the same folder where php-cgi.exe is located.
具体设置请参考IIS官方说明:Using FastCGI to Host PHP Applications on IIS 7.0

永远爱你 发表于 2015-3-8 23:36:54

这个很有用,但是觉得server不适合初学者,多谢楼主无私分享
页: [1]
查看完整版本: windows 2008 R2 下 IIS7.5+PHP+Mysql+Zend完美运行fastcgi