Windows 系统下的安装
在线手册:中文 英文
PHP手册

Microsoft IIS 5.1 and IIS 6.0

This section contains instructions for manually setting up Internet Information Services (IIS) 5.1 and IIS 6.0 to work with PHP on Microsoft Windows XP and Windows Server 2003. For instructions on setting up IIS 7.0 and later versions on Windows Vista, Windows Server 2008, Windows 7 and Windows Server 2008 R2 refer to Microsoft IIS 7.0 and later.

Configuring IIS to process PHP requests

Download and install PHP in accordance to the instructions described in manual installation steps

Note:

Non-thread-safe build of PHP is recommended when using IIS. The non-thread-safe builds are available at » PHP for Windows: Binaries and Sources Releases.

Configure the CGI- and FastCGI-specific settings in php.ini file as shown below:

Example #1 CGI and FastCGI settings in php.ini

fastcgi.impersonate = 1
fastcgi.logging = 0
cgi.fix_pathinfo=1
cgi.force_redirect = 0

Download and install the » Microsoft FastCGI Extension for IIS 5.1 and 6.0. The extension is available for 32-bit and 64-bit platforms - select the right download package for your platform.

Configure the FastCGI extension to handle PHP-specific requests by running the command shown below. Replace the value of the "-path" parameter with the absolute file path to the php-cgi.exe file.

Example #2 Configuring FastCGI extension to handle PHP requests

cscript %windir%\system32\inetsrv\fcgiconfig.js -add -section:"PHP" ^
-extension:php -path:"C:\PHP\php-cgi.exe"

This command will create an IIS script mapping for *.php file extension, which will result in all URLs that end with .php being handled by FastCGI extension. Also, it will configure FastCGI extension to use the executable php-cgi.exe to process the PHP requests.

Note:

At this point the required installation and configuration steps are completed. The remaining instructions below are optional but highly recommended for achieving optimal functionality and performance of PHP on IIS.

Impersonation and file system access

It is recommended to enable FastCGI impersonation in PHP when using IIS. This is controlled by the fastcgi.impersonate directive in php.ini file. When impersonation is enabled, PHP will perform all the file system operations on behalf of the user account that has been determined by IIS authentication. This ensures that even if the same PHP process is shared across different IIS web sites, the PHP scripts in those web sites will not be able to access each others' files as long as different user accounts are used for IIS authentication on each web site.

For example IIS 5.1 and IIS 6.0, in its default configuration, has anonymous authentication enabled with built-in user account IUSR_<MACHINE_NAME> used as a default identity. This means that in order for IIS to execute PHP scripts, it is necessary to grant IUSR_<MACHINE_NAME> account read permission on those scripts. If PHP applications need to perform write operations on certain files or write files into some folders then IUSR_<MACHINE_NAME> account should have write permission to those.

To determine which user account is used by IIS anonymous authentication, follow these steps:

  1. In the Windows Start Menu choose "Run:", type "inetmgr" and click "Ok";

  2. Expand the list of web sites under the "Web Sites" node in the tree view, right-click on a web site that is being used and select "Properties";

  3. Click the "Directory Security" tab;

  4. Take note of a "User name:" field in the "Authentication Methods" dialog

Anonymous authenication for IIS 5.1 and IIS 6.0

To modify the permissions settings on files and folders, use the Windows Explorer user interface or icacls command.

Example #3 Configuring file access permissions

icacls C:\inetpub\wwwroot\upload /grant IUSR:(OI)(CI)(M)

Set index.php as a default document in IIS

The IIS default documents are used for HTTP requests that do not specify a document name. With PHP applications, index.php usually acts as a default document. To add index.php to the list of IIS default documents, follow these steps:

  1. In the Windows Start Menu choose "Run:", type "inetmgr" and click "Ok";

  2. Right-click on the "Web Sites" node in the tree view and select "Properties";

  3. Click the "Documents" tab;

  4. Click the "Add..." button and enter "index.php" for the "Default content page:".

Setting index.php as default document for IIS

FastCGI and PHP Recycling configuration

Configure IIS FastCGI extension settings for recycling of PHP processes by using the commands shown below. The FastCGI setting instanceMaxRequests controls how many requests will be processed by a single php-cgi.exe process before FastCGI extension shuts it down. The PHP environment variable PHP_FCGI_MAX_REQUESTS controls how many requests a single php-cgi.exe process will handle before it recycles itself. Make sure that the value specified for FastCGI InstanceMaxRequests setting is less than or equal to the value specified for PHP_FCGI_MAX_REQUESTS.

Example #4 Configuring FastCGI and PHP recycling

cscript %windir%\system32\inetsrv\fcgiconfig.js -set -section:"PHP" ^
-InstanceMaxRequests:10000

cscript %windir%\system32\inetsrv\fcgiconfig.js -set -section:"PHP" ^
-EnvironmentVars:PHP_FCGI_MAX_REQUESTS:10000

Configuring FastCGI timeout settings

Increase the timeout settings for FastCGI extension if there are applications that have long running PHP scripts. The two settings that control timeouts are ActivityTimeout and RequestTimeout. Refer to » Configuring FastCGI Extension for IIS 6.0 for more information about those settings.

Example #5 Configuring FastCGI timeout settings

cscript %windir%\system32\inetsrv\fcgiconfig.js -set -section:"PHP" ^
-ActivityTimeout:90

cscript %windir%\system32\inetsrv\fcgiconfig.js -set -section:"PHP" ^
-RequestTimeout:90

Changing the Location of php.ini file

PHP searches for php.ini file in several locations and it is possible to change the default locations of php.ini file by using PHPRC environment variable. To instruct PHP to load the configuration file from a custom location run the command shown below. The absolute path to the directory with php.ini file should be specified as a value of PHPRC environment variable.

Example #6 Changing the location of php.ini file

cscript %windir%\system32\inetsrv\fcgiconfig.js -set -section:"PHP" ^
-EnvironmentVars:PHPRC:"C:\Some\Directory\"


Windows 系统下的安装
在线手册:中文 英文
PHP手册
PHP手册 - N: Microsoft IIS 5.1 and IIS 6.0

用户评论:

bjorn dot tornroth at nettitonttu dot fi (12-Feb-2012 05:45)

If you receive:

Input Error: There is no script engine for file extension ".js".

When executing:

cscript %windir%\system32\inetsrv\fcgiconfig.js -add -section:"PHP" -extension:php -path:"C:\PHP\php-cgi.exe"

Include the switch:

/e:jscript

Like this:

cscript /e:jscript %windir%\system32\inetsrv\fcgiconfig.js -add -section:"PHP" -extension:php -path:"C:\PHP\php-cgi.exe"

Worked on freshly installed XP Pro ENG SP3(updated).

Anonymous (10-Feb-2012 10:53)

I am using Win 2003 Server SP2, IIS 6, Installing PHP 5.3.10 as FastCGI

If you continue to receive FastCGI could not proccess your request - Access Denied Error -5 check to make sure the IIS_WPG Group has Read, Read/Execute permission to the PHP installation directory and is inherited to the php-cgi.exe file.

Also, in researching this problem during my installation, I also found that you should have an entry in the IIS Web Extensions for the php-cgi.exe.

koen dot bauwens at fracarita dot org (08-Sep-2011 08:42)

When executing:

cscript %windir%\system32\inetsrv\fcgico
nfig.js -add -section:"PHP" ^
More? -extension:php -path:"C:\PHP\php-cgi.exe"

You get this response:

Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

C:\WINDOWS\system32\inetsrv\fcgiconfig.js(1348, 5) (null): 0xFFFFFFDF

Then check if in the C:\WINDOWS\system32\inetsrv\fcgiext.ini file the next text is present:

[Types]
php=c:\php\php-cgi.exe

[c:\php\php-cgi.exe]
QueueLength=999
MaxInstances=20
InstanceMaxRequests=10000
IdleTimeout=90
RequestTimeout=90

If not, add it, worked for me!

gsaarenvirta at makeplain dot com (14-Mar-2011 12:49)

A note for your reference ... I was getting error 404 "file not found when trying to browse .php" files in \inetpub\wwwroot although .html files worked fine... messed around for hours until I tried this on advice of a friend.

FYI ...

Operating system Windows Server 2003 SP2 x64
IIS v6.0
PHP v 5.3.5 nts windows x86
Microsoft C++ 2008 redistributable
no fastcgi

Followed all the manual PHP configuration instructions very carefully, set php.ini directives, gave appropriate permissions to "IUSR_(machine)", set up web extensions etc. etc.

The final fix that made everything work... renamed 'php.ini' to 'php-cgi-fcgi.ini'

Hope this saves someone hours...

crab dot crab at gmail dot com (19-Nov-2010 07:40)

I am using Win 2003 Server, IIS 6, PHP 5.

If you see "You are not authorized to view this page" error when running your PHP page.

Try one more thing:
1. Right-click {C:\php} (or your PHP installation root) and select {Properties}
2. Select {Security} tab and click {Add} button
3. Enter {ComputerName/IUSR_ComputerName} as object name and press {OK}
4. Select {Read & Execute} as permissions
5. Click {Advanced} button and select {Allow inheritable permissions from the parent...} checkbox
6. Press {OK}

Anonymous (12-Oct-2010 09:49)

Facts: WinXp Pro, IIS 5.1, add extension ".php" to default web site, Ok button disabled from application configuration mapping after setting the path to executable

Solution: Click inside the textbox after setting the path will enable ok button

Source: http://support.microsoft.com/?id=317948

Anonymous (15-Sep-2010 06:29)

i`ve the same trouble after the install php 5.2.14-nts on IIS6 (Win2003Server)- try to open-dialog when php-file is opening...

I`ve to manual add .php in "Application configuration"  ... \system32\inetsrv\fcgiext.dll  (even this option selected in installation - "Script executable")

this solved the problem :)

Neil Plumridge (24-Aug-2010 03:00)

Using WinXP/SP3, IIS5.1, I found that following the instructions added the .PHP file association to the 'Web Sites' level in the IIS Manager, but when I tried to access a PHP page my browser tried to download it.  I had to add the same .PHP file association to the 'Default Web Site' configuration too.

joseph dot dew at metso dot com (29-Jun-2010 05:44)

Using PHP 5.3.2 non thread safe VC9 I had to copy the php.ini to php-cgi-fcgi.ini otherwise I just got 404 errors.