©
このドキュメントでは、 php中国語ネットマニュアル リリース
本章包含有在 Windows XP 和 Windows Server 2003 下的 Internet 信息服务(IIS)5.1 和 IIS 6.0 中安装 PHP 的指南。有关在 Windows Vista,Windows Server 2008,Windows 7 以及 Windows Server 2008 R2 下的 IIS 7.0 以及更高版本中安装 PHP 的指南见 Microsoft IIS 7.0 及更高版本一章。
根据手工安装步骤的说明下载和安装 PHP。
Note:
在使用 IIS 时推荐使用非线程安全的 PHP。可以在 » PHP for Windows: Binaries and Sources Releases 下载。
按以下示例在 php.ini 文件中配置 针对 CGI- 和 FastCGI- 的指令:
Example #1 php.ini 中的 CGI 和 FastCGI 设定
fastcgi.impersonate = 1 fastcgi.logging = 0 cgi.fix_pathinfo=1 cgi.force_redirect = 0
下载并安装 » FastCGI for IIS。有 32 位和 64 位平台的,根据用户平台选择相应的下载。
用以下命令配置 FastCGI 扩展处理 PHP 请求。用指向 php-cgi.exe 文件的绝对路径替换其中的 "-path" 的参数。
Example #2 配置 FastCGI 扩展以处理 PHP 请求
cscript %windir%\system32\inetsrv\fcgiconfig.js -add -section:"PHP" ^ -extension:php -path:"C:\PHP\php-cgi.exe"
此命令将创建对应于 *.php 文件后缀的 IIS 脚本映射,则所有以 *.php 结尾的 URL 都会被 FastCGI 扩展处理。此外还配置了 FastCGI 扩展使用 php-cgi.exe 可执行文件来处理 PHP 请求。
Note:
至此所需的安装和配置步骤就完成了。以下剩余的指示是可选项,但是强烈推荐以使得在 IIS 上达到最佳的 PHP 功能和性能。
在 IIS 中使用 PHP 建议激活 FastCGI 的角色扮演功能。此功能在 php.ini 中由 fastcgi.impersonate 指令控制。激活角色扮演后,PHP 将以 IIS 所认证的用户帐号身份进行所有的文件系统操作。这将确保即使在(同一个主机)不同的 IIS 网站下使用了同一个 PHP 进程,只要每个网站使用了不同的用户帐号作为 IIS 身份认证,则这些网站的 PHP 脚本将不能访问彼此的文件。
例如在 IIS 5.1 和 IIS 6.0 中,默认配置下的匿名认证将使用内置的用户帐号 IUSR_<MACHINE_NAME> 作为默认身份。这意味着要使得 IIS 能够运行 PHP 脚本,至少要将这些脚本的读取权限授予 IUSR_<MACHINE_NAME> 帐号。如果 PHP 程序需要对某些文件或文件夹进行写入操作,那 IUSR_<MACHINE_NAME> 帐号也需要有相对应的写入权限。
要查看哪个用户帐号被用作 IIS 匿名认证的身份,使用以下步骤:
在 Windows 开始菜单中选择“运行...”,输入“inetmgr”并点击“确定”;
在树形视图下展开“网站”节点,右键点击要使用的网站并选择“属性”;
点击“目录安全”面板;
记录下在“认证方式”对话框中的“用户名”字段。
要修改文件及文件夹的权限,使用 Windows 资源管理器或者 icacls 命令行。
Example #3 配置文件访问权限
icacls C:\inetpub\wwwroot\upload /grant IUSR:(OI)(CI)(M)
IIS 的默认文档用于没有指定文件名的 HTTP 请求。对于 PHP 应用来说默认文档通常为 index.php。要将 index.php 添加到 IIS 的默认文档列表中,使用以下步骤:
在 Windows 开始菜单中选择“运行...”,输入“inetmgr”并点击“确定”;
在树形视图下展开“网站”节点,右键点击要使用的网站并选择“属性”;
点击“文档”面板;
点击“添加...”按钮并在“默认内容页面”中输入“index.php”。
用以下命令配置 IIS FastCGI 对于 PHP 进程的回收设定。FastCGI 的设置 instanceMaxRequests 控制了单一的 php-cgi.exe 进程处理多少个请求之后会被 IIS 关闭。PHP 环境变量 PHP_FCGI_MAX_REQUESTS 控制了一个 php-cgi.exe 进程处理多少个请求之后会被自我回收。要确保 FastCGI 中 InstanceMaxRequests 的值小于或等于 PHP_FCGI_MAX_REQUESTS 的值。
Example #4 配置 FastCGI 和 PHP 的回收
cscript %windir%\system32\inetsrv\fcgiconfig.js -set -section:"PHP" ^ -InstanceMaxRequests:10000cscript %windir%\system32\inetsrv\fcgiconfig.js -set -section:"PHP" ^ -EnvironmentVars:PHP_FCGI_MAX_REQUESTS:10000
如果会有一些需时较长的 PHP 脚本运行,则增加超时的设定值。有两个控制超时的指令 activityTimeout 和 requestTimeout 。有关这些设定的更多信息参见 » Configuring FastCGI Extension for IIS 6.0。
Example #5 配置 FastCGI 超时设定
cscript %windir%\system32\inetsrv\fcgiconfig.js -set -section:"PHP" ^ -ActivityTimeout:90cscript %windir%\system32\inetsrv\fcgiconfig.js -set -section:"PHP" ^ -RequestTimeout:90
PHP 在几个位置搜索配置文件 php.ini,可以通过环境变量 PHPRC 来改变 php.ini 的默认位置。要使得 PHP 从用户指定的位置加载配置文件,使用以下命令。指向 php.ini 文件的绝对路径应作为环境变量 PHPRC 的值。
Example #6 改变 php.ini 文件的位置
cscript %windir%\system32\inetsrv\fcgiconfig.js -set -section:"PHP" ^ -EnvironmentVars:PHPRC:"C:\Some\Directory\"
[#1] jeanchristophe dot vanhalle at gmail dot com [2015-07-02 20:11:36]
If your PHP script displays `No input file specified' and you followed the instructions (for IIS 5.1 and windows XP) you might have to set up ACL on Windows\TEMP so that the IUSR accessing the page has right and write access on that folder.
[#2] pythonex12 at gmail dot com [2014-02-23 19:27:21]
I used Windows 2003 Server, IIS 6.0, MS SQL Server 2008, and PHP 5.3 along with FastCGI. If, after following the set up step-by-steps, you continually get a FastCGI 500 timeout error check your MS SQL Server PHP driver.
MS SQL Server PHP driver 3.0 which was updated on 04/18 requires you have the 2012 MS SQL Server Native Client (v 11). But if you are using MS SQL Server 2008 like I was you only have the 2008 MS SQL Server Native Client (v 10). For whatever reason I could not get the 2012 Native CLient to install on the OS even though it appeared MS's website said it should be able to.
So just downgrade to the MS SQL Server PHP driver 2.0. The site says it will be deprecated but at least you can get up and running for a while until you have to upgrade your OS and MS SQL Server.
This kinda drove me nuts for a few hours.
[#3] renigade1 at can-d dot net [2012-10-27 20:01:56]
If you still receive 404 errors... try this...
I had to:
1) right click on My Computer, select Manage
2) open up "Services and Applications" -> "Internet Information Services" -> "Web Sites" -> mywebsite (where mywebsite could be "Default Web Site" or whatever my web site is named)
3) right-click on mywebsite and select Properties
choose the "Home Directory" tab, select Configuration... button
4) either select the .php extension and choose the Edit... button, or if .php isn't listed then press the Add... button
5) make the Executable C:\WINDOWS\system32\inetsrv\fcgiext.dll, the extension .php, and ensure Verbs are limited to GET,HEAD,POST, check the "Script engine" and "Verify that file exists" check boxes
Once I did this I at least now get the 500 fastcgi error
[#4] Simon Elms [2012-09-04 04:47:01]
Installing PHP 5.4 on Windows Server 2003 R2 Standard Edition with IIS 6:
Issue: After installing PHP I was getting 404 errors on all .php pages, even if I browsed from within IIS Manager.
Solution: Add a PHP Web Service Extension:
In IIS Manager, expande the local computer node on the left and right-click on Web Service Extensions. From the context menu select "Add a new Web service extension..."
In the New Web Service Extension dialog:
Extension name: PHP
Required files: Add... path to php.exe (eg C:\PHP\php.exe)
Set status of new web service extension to Allowed.
NOTE: Seems to work equally well if you use the path to php.exe or php-cgi.exe.
[#5] Anonymous [2012-05-20 01:25:54]
When installing PHP 5.3 on IIS by following the manual installation steps described here (http://www.php.net/manual/en/install.windows.iis6.php) and here (http://www.php.net/manual/en/install.windows.iis7.php) it is possible to get the following error from FastCGI:
HTTP Error 500.0 - Internal Server Error
Module: FastCgiModule
Notification: ExecuteRequestHandler
Handler: php-5.3.6
Error code: 0x800736b1
The reason this error happens is because PHP 5.3 is built by using Visual C++ 2008 compiler (VC9) and hence requires Visual C++ 2008 runtime to be installed on the machine. This error does not happen when PHP 5.3 is installed by Web Platform Installer or if you already have URL Rewrite module installed.
To fix the error download and install Visual C++ 2008 runtime from here:
http://www.microsoft.com/downloads/en/details.aspx?familyid=9b2da534-3e03-4391-8a4d-074b9f2bc1bf&displaylang=en
(Make sure to use x86 version even if you have x64 environment)
[#6] Refrito [2012-04-22 09:57:59]
Using Win 2003 Server, IIS 6, PHP 5. If after running the command:
cscript fcgiconfig.js -add -section:"PHP" -extension:"php" -path:"C:\PHP\php-cgi.exe"
(with the right quotation as pointed in a previous note)
You get the following error/message:
C:\WINDOWS\system32\inetsrv\fcgiconfig.js(1326, 5) (null): 0xFFFFFFDF
It may be because you have a previous version of C:\WINDOWS\system32\inetsrv\fcgiext.ini. So backup the file and make a clean one with only an empty [types] section. Run the command again and it should work.
[#7] stpetersn at Hotmail dot com [2012-04-19 17:50:17]
I used Windows 2003 Server, IIS 6.0, MS SQL Server 2008, and PHP 5.3 along with FastCGI. If, after following the set up step-by-steps, you continually get a FastCGI 500 timeout error check your MS SQL Server PHP driver.
MS SQL Server PHP driver 3.0 which was updated on 04/18 requires you have the 2012 MS SQL Server Native Client (v 11). But if you are using MS SQL Server 2008 like I was you only have the 2008 MS SQL Server Native Client (v 10). For whatever reason I could not get the 2012 Native CLient to install on the OS even though it appeared MS's website said it should be able to.
So just downgrade to the MS SQL Server PHP driver 2.0. The site says it will be deprecated but at least you can get up and running for a while until you have to upgrade your OS and MS SQL Server.
This kinda drove me nuts for a few hours.
[#8] bjorn dot tornroth at nettitonttu dot fi [2012-02-12 09:45:13]
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).
[#9] Anonymous [2012-02-10 14:53:29]
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.
[#10] koen dot bauwens at fracarita dot org [2011-09-08 00:42:07]
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!
[#11] gsaarenvirta at makeplain dot com [2011-03-13 16:49:13]
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...
[#12] crab dot crab at gmail dot com [2010-11-18 23:40:28]
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}
[#13] Anonymous [2010-09-14 22:29:34]
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 :)