Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學

為 Windows Vista/Server 2008 IIS 7.0 加入 PHP (FastCGI/ISAPI) 支援完整教學

編輯:Windows 2003 常見問題解答

Windows Server 2008 IIS 7.0 原生支援 FastCGI,執行 PHP 效能較舊版 IIS 大幅提升。本文示範以 ISAPI 方式整合 PHP (適用既有 PHP 程式碼遷移),並說明關鍵設定檔調整。

系統環境

  • Windows Vista / Windows Server 2008 (含 R2)。
  • IIS 7.0 已安裝 (「開啟或關閉 Windows 功能」→「Internet 資訊服務」→ 勾選「ISAPI 擴充功能」、「ISAPI 篩選器」)。

步驟 1:安裝 PHP

  1. 下載 Windows 版 PHP (Non Thread Safe 或 Thread Safe 均可) → 解壓至 D:\PHP。
  2. 複製 php.ini-dist 為 php.ini,編輯關鍵項:
    extension_dir = "D:\PHP"
    啟用常用擴充 (移除前方分號):
    extension=php_mbstring.dll
    extension=php_gd2.dll
    extension=php_mysql.dll (或 php_mysqli.dll)
    cgi.force_redirect = 0 (ISAPI 模式必須)
    fastcgi.impersonate = 1 (若改用 FastCGI 需要)
  3. 將 php.ini 複製至 %SystemRoot% (通常 C:\Windows)。

步驟 2:建立應用程式集區

  1. IIS 管理員 → 「應用程式集區」→「新增應用程式集區」。
  2. 名稱:PHP_Pool、.NET CLR 版本:無受控碼、管道模式:整合 或 傳統 均可。

步驟 3:建立網站並設定權限

  1. 「網站」→「新增網站」→ 綁定 IP/連接埠/主機名、實體路徑指向 PHP 專案目錄。
  2. 該網站「基本設定」→ 指派上一步建立的 PHP_Pool。
  3. 「處理常式對應」→ 「編輯功能權限」→ 勾選「讀取」、「執行指令碼」。

步驟 4:新增 ISAPI 篩選器

網站層級 → 「ISAPI 篩選器」→「新增」→ 篩選器名稱 PHP_ISAPI、可執行檔 D:\PHP\php5isapi.dll → 確定。

步驟 5:新增處理常式對應

網站層級 → 「處理常式對應」→「新增指令碼對應」→
要求路徑:*.php
執行檔:D:\PHP\php5isapi.dll
名稱:PHP_via_ISAPI → 確定。
提示「是否允許此 ISAPI 擴充功能?」選「是」。

步驟 6:驗證

網站根目錄建立 info.php:

瀏覽 https://<站點>/info.php 應顯示 PHP 資訊頁。

補充:改用 FastCGI (效能更佳)

  1. 安裝 FastCGI 元件 (Server 2008 R2 內建,Vista/Server 2008 需另裝)。
  2. php.ini 設 cgi.force_redirect=0、fastcgi.impersonate=1。
  3. 處理常式對應改指向 D:\PHP\php-cgi.exe,模組改為 FastCgiModule。
  4. IIS 管理員 → 「FastCGI 設定」→ 新增應用程式 D:\PHP\php-cgi.exe、執行個體上限視 CPU 核心數調整。

完成上述設定,IIS 7.0 即可穩定高效執行 PHP 應用程式。

Copyright © Windows教程網 All Rights Reserved