下午在公司已經(jīng)可以在 Windows Server 2008 和 IIS 7 下跑 PHP 了,家里是 Windows Server 2003 和 IIS 6 的,雖然之前也可以跑過 PHP,但覺得過程糊里糊涂,不知所以然,google 一翻,終于實(shí)現(xiàn)手工配置 IIS 6 下以 FastCGI 跑 PHP。回頭把 IIS 7 下的實(shí)現(xiàn)方法也帖上。
環(huán)境:
操作系統(tǒng):Windows 2003 Server SP2
PHP 版本:php-5.2.6-Win32
1.下載 FastCGI For IIS6
http://www.microsoft.com/downloads/details.aspx?FamilyID=2d481579-9a7c-4632-b6e6-dee9097f9dc5&displaylang=en
下載之后,雙擊運(yùn)行進(jìn)行安裝。
安裝后在 C:\WINDOWS\system32\inetsrv 目錄下產(chǎn)生了五個(gè)文件。如下圖:

同時(shí)在 IIS 的 “Web 服務(wù)擴(kuò)展”里多了 FastCGI Handler。

2.下載 PHP5.25 Windows 版
http://www.php.net/downloads.php
下載 .zip 格式的版本,下載后解壓至 D:\PHP 目錄,并給 IIS 啟動(dòng)帳戶組或用戶賦予讀取和運(yùn)行權(quán)限。如下圖:

你可以根據(jù)自己的意愿解壓到別的目錄。
3. 注冊(cè) 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.
我個(gè)人的理解是,只要“Web 服務(wù)擴(kuò)展”里的 FastCGI Handler 為允許時(shí),在加載 fcgiext.dll 時(shí),會(huì)讀取 fcgiext.ini 配置文件的內(nèi)容,根據(jù)里面的配置為每個(gè)網(wǎng)站提供映射。
在 [Types] 下添加以下配置:
[Types]
php=PHP
[PHP]
ExePath=D:\PHP\php-cgi.exe
“php”表示擴(kuò)展名,“PHP”是配置節(jié)名稱,以“[PHP]”定義。
4. 配置 php.ini
將 D:\PHP\php.ini-recommended 復(fù)制一個(gè),然后重命名為 D:\PHP\php.ini
打開 D:\PHP\php.ini,修改:
extension_dir = "D:\PHP\ext"
fastcgi.impersonate = 1
其它的根據(jù)實(shí)際需要對(duì) php.ini 進(jìn)行設(shè)置修改,這里只針對(duì)能跑 php,修改完記得重啟 IIS。
5. 配置網(wǎng)站
右鍵網(wǎng)站 => 屬性 => 主目錄 => 配置 => 添加,如下圖配置:

可執(zhí)行文件路徑:C:\WINDOWS\system32\inetsrv\fcgiext.dll
6. 寫個(gè) php 測試下吧
<?php
phpinfo();
?>
看到類似以下效果說明你的服務(wù)器可以跑 php 了。

打開后如果出現(xiàn)提示:
No input file specified.
估計(jì)是沒配置 fastcgi.impersonate。
如果覺得過程麻煩,請(qǐng)看:
http://hi.baidu.com/imdao/blog/item/16583512f11cb654f819b858.html
如果你還覺得麻煩,那就到 http://www.zend.com 下載 Zend Core,這個(gè)就什么都不用配置,安裝完就可以使用了,連 MySQL 都有。
PS:PHP 5.3.0 安裝有一個(gè)注意事項(xiàng),詳細(xì):http://www.itlibs.com/tech/archive/20090813/135989.html