iis7.5+php5.2.17+Zend Optimizer(FastCGI)配置

在windows2008下配置PHP5.2.17TS版。

Enable FastCGI Support in IIS

Windows Server 2008

Go to Server Manager -> Roles -> Add Role Services. On the Select Role Services page, select the CGI check box. This enables both the CGI and FastCGI services.

using-fastcgi-to-host-php-applications-on-iis-246-IIS20-20Enable20FastCGI20Role

Install and Configure PHP

It is recommended that you use a non-thread safe build of PHP with IIS FastCGI. A non-thread safe build of PHP provides significant performance gains over the standard build by not doing any thread-safety checks, which are not necessary, since FastCGI ensures a single threaded execution environment.

To install PHP:

Download the latest non-thread safe zip package with binaries of PHP: http://www.php.net/downloads.php.

Unpack the files to the directory of your choice (e.g. C:\PHP). Rename the php.ini-recommended file to php.ini.

Open the php.ini file. Uncomment and modify the settings as follows:

Set fastcgi.impersonate = 1. FastCGI under IIS supports the ability to impersonate security tokens of the calling client. This allows IIS to define the security context that the request runs under.

Set cgi.fix_pathinfo=1. cgi.fix_pathinfo provides real PATH_INFO/PATH_TRANSLATED support for CGI. Previously, PHP behavior was to set PATH_TRANSLATED to SCRIPT_FILENAME, and to not define PATH_INFO. For more information about PATH_INFO, see the cgi specifications. Setting this value to 1 will cause PHP CGI to fix its paths to conform to the specifications.

Set cgi.force_redirect = 0.

Set open_basedir to point to the folder or network path where the content of the Web site(s) is located.

Set extension_dir to point to the location where the PHP extensions are located. Typically, for PHP 5.2.X the value would be set as extension_dir = "./ext"

Enable the required PHP extension by un-commenting the corresponding lines, for example:
extension=php_mssql.dll extension=php_mysql.dll

Open a command prompt, and run the following command to verify that PHP installed successfully:

C:\PHP>php –infoIf PHP installed correctly and all its dependencies are available on the machine, this command will output the current PHP configuration information.

Configure IIS to Handle PHP Requests

For IIS to host PHP applications, you must add a handler mapping that tells IIS to pass all PHP-specific requests to the PHP application framework by using the FastCGI protocol.

Configure IIS to handle PHP requests by using IIS Manager

  1. Open IIS Manager. At the server level, double-click Handler Mappings.

using-fastcgi-to-host-php-applications-on-iis-246-handler20mappings

  1. In the Actions pane, click Add Module Mapping.... In the Add Module Mapping dialog box, specify the configuration settings as follows:

    • Request path: *.php
    • Module: FastCgiModule
    • Executable: "C:\[Path to your PHP installation]\php-cgi.exe"
    • Name: PHP via FastCGI

     

  2. Click OK.

using-fastcgi-to-host-php-applications-on-iis-246-add20module20mapping

  1. In the Add Module Mapping confirmation dialog box that asks if you want to create a FastCGI application for this executable, click Yes.

using-fastcgi-to-host-php-applications-on-iis-246-file3

  1. Test that the handler mapping works correctly by creating a phpinfo.php file in the C:\inetpub\wwwroot folder that contains the following code:

<?php phpinfo(); ?>6. Open a browser and navigate to http://localhost/phpinfo.php. If everything was setup correctly, you will see the standard PHP information page.

using-fastcgi-to-host-php-applications-on-iis-246-phpinfo

PHP Process Recycling Behavior

Ensure that FastCGI always recycles the php-cgi.exe processes before the native PHP recycling kicks in. The FastCGI process recycling behavior is controlled by the configuration property instanceMaxRequests. This property specifies how many requests the FastCGI process will process before recycling. PHP also has a similar process recycling functionality that is controlled by the environment variable PHP_FCGI_MAX_REQUESTS. By setting instanceMaxRequests to be less than or equal to PHP_FCGI_MAX_REQUESTS, you can ensure that the native PHP process recycling logic will never kick in.

The FastCGI settings can be configured either by using IIS Manager or by using the command line tool AppCmd.

Configure FastCGI recycling settings by using IIS Manager

  1. Ensure that the Administration Pack for IIS is installed on your server. Open IIS Manager. On the server level, double-click FastCGI Settings.

using-fastcgi-to-host-php-applications-on-iis-246-fast20cgi

 

  1. Select the FastCGI application that you want to configure. In the Actions pane, click Edit....

using-fastcgi-to-host-php-applications-on-iis-246-fastcg20edit20button

 

  1. In the Edit FastCGI Application dialog box, set the InstanceMaxRequests to 10000. Next to the EnvironmentVariables setting, click the Browse (...) button.

using-fastcgi-to-host-php-applications-on-iis-246-FastCGIAppSettings

  1. In the EnvironmentVariables Collection Editor dialog box, add the PHP_FCGI_MAX_REQUESTS environment variable and set its value to 10000.

using-fastcgi-to-host-php-applications-on-iis-246-SetEnvVariable