在IIS6下配置官方的FASTCGI使用PHP
March 20, 2008
1.首先到微軟官方IIS網站下載,並安裝 FastCGI Extension for IIS6.0 - RTM
http://www.iis.net/downloads/default.aspx?tabid=34&g=6&i=1521
(安裝後不需要重啟SERVER)
2.設置IIS
設置支持.php文件
- Double click the machine icon for the local computer
- Right click on “Web Sites” and pick “Properties”
- Click on the tab labeled “Home Directory”
- Click on the “Configuration…” button.
- Click on the “Add…” button.
- Browse to %WINDIR%\system32\inetsrv\ to select fcgiext.dll as the Executable.
- Enter .php as the Extension
- Select “All verbs”
- Ensure that “Script Engine” and “Verify that file exists” are checked.

添加影射
設置默認首頁
- Double click the machine icon for the local computer.
- Right click “Web Sites” and pick “Properties.”
- Click the “Documents” tab.
- Click the “Add…” button and enter “index.php” for “Default Document Name:”
- Click “OK.”
3.配置PHP FastCGI
編輯%WINDIR%\system32\inetsrv\fcgiext.ini
在[Types]下面加入
PHP=C:\PHP\php-cgi.exe
[C:\PHP\php-cgi.exe]
QueueLength=1000
MaxInstances=4
InstanceTimeout=30
InstanceMaxRequests=200
上面的參數根據實際環境進行配置
configuration settings (per process pool):
fullPath: path to application for this pool (e.g. d:\php\php-cgi.exe, NOTE: must match handlers section)
maxInstances: maximum number of processes to create in this pool
instanceTimeout: maximum duration a request can last
instanceMaxRequests: process will be retired after exceeding this number of requests
protocol: use named pipes or tcp. The tech preview currently only supports named pipes, but TCP should be simple to add.
queueLength: maximum number of requests to queue (when this is exceeded the module will start 500'ing)
flushNamedPipe: Flush the named pipe at the end of each request. This is to workaround, what seems to be a bug in libfcgi: if two FastCGI requests arrive in a single ReadFile call, libfcgi closes the pipe. (If anyone wants to tackle this problem, I'd be happy to provide a repro)
4.配置php.ini
設置好extension_dir並打開需要的extension
; fastcgi.impersonate = 1; 改成 fastcgi.impersonate = 1
; cgi.fix_pathinfo=1 改成 cgi.fix_pathinfo=1
; cgi.force_redirect = 1 改成 cgi.force_redirect = 0
更詳細的安裝說明可以參考
%WINDIR%\system32\inetsrv\fcgireadme.htm
http://learn.iis.net/page.aspx/247/using-fastcgi-to-host-php-applications-on-iis-60/
PS
當你已經打開過php文件後,你再去修改php.ini必須用命令行重啟IIS才會生效
net stop w3svc
net start w3svc






