環境:
作業系統:Windows 2003 Server SP2
PHP 版本:php-5.2.6-Win32
1.下載 FastCGI For IIS6
http://www.iis.net/download/fastcgi
下載之後,雙擊運行進行安裝。
安裝後在 C:\WINDOWS\system32\inetsrv 目錄下產生了五個檔案。如:
- fcgiext.dll – fastcgi處理常式
- fcgiext.ini – 設定檔
- fcgiconfig.js – FastCGI的控制指令碼
同時在 IIS 的 “Web 服務擴充”裡多了 FastCGI Handler。
2.下載 PHP5.2.14 Windows 版
http://www.php.net/downloads.php
下載 .zip 格式的版本,下載後解壓至 c:\PHP 目錄,並給 IIS 啟動帳戶組或使用者賦予讀取和運行許可權。如:
你可以根據自己的意願解壓到別的目錄。
3. 註冊 PHP 到 FastCGI
開啟 C:\WINDOWS\system32\inetsrv\fcgiext.ini 檔案。
; This is the configuration file for the FastCGI handler for IIS 6.0.
; The FastCGI handler will look for this file in the same directory as
; fcgiext.dll. By default, the FastCGI installer will place this file into
; the %windir%\system32\inetsrv directory.
我個人的理解是,只要“Web 服務擴充”裡的 FastCGI Handler 為允許時,在載入 fcgiext.dll 時,會讀取 fcgiext.ini 設定檔的內容,根據裡面的配置為每個網站提供映射。
在 [Types] 下添加以下配置:
[Types]
php=PHP
[PHP]
ExePath=C:\PHP\php-5.2.14-Win32\php-cgi.exe
“php”表示副檔名,“PHP”是配置節名稱,以“[PHP]”定義。
4. 配置 php.ini
將 C:\PHP\php-5.2.14-Win32\php.ini-recommended 複製一個,然後重新命名為 D:\PHP\php.ini
開啟 C:\PHP\php-5.2.14-Win32\php.ini,修改:
extension_dir = "C:\PHP\php-5.2.14-Win32\ext"
fastcgi.impersonate = 1
其它的根據實際需要對 php.ini 進行設定修改,這裡只針對能跑 php,修改完記得重啟 IIS。
5. 配置網站
右鍵網站 => 屬性 => 主目錄 => 配置 => 添加,如配置:
可執行檔路徑:C:\WINDOWS\system32\inetsrv\fcgiext.dll
6. 寫個 php 測試下吧
<?php
phpinfo();
?>
看到類似以下效果說明你的伺服器可以跑 php 了。
開啟後如果出現提示:No input file specified. 估計是沒配置 fastcgi.impersonate。
參考 http://hi.baidu.com/imdao/blog/item/16583512f11cb654f819b858.html
Configure the FastCGI Extension for IIS 6.0