2008年11月28日

[Server] Windows 下執行 Apache 2.0 + PHP5 + FastCGI

這兩天在研究如何讓 PHP 在 FastCGI 模式下執行,目前成功地執行了,這裡做個小記錄:

mod_fastcgi 安裝說明

首先我假定大家已經安裝好了 Apache 2.0(Win32) ,那麼我們只需要安裝好 mod_fastcgi 就可以了:

先到以下網址下載 mod_fastcgi 2.4.2 for Apache 2.0 版本:

http://www.fastcgi.com/dist/old/mod_fastcgi-2.4.2-AP20.dll

下載回來後儲存到 Apache 安裝目錄的 modules 下。

然後在 httpd.conf 加入以下設定:

# FastCGI Module
LoadModule fastcgi_module modules/mod_fastcgi-2.4.2-AP20.dll

<IfModule mod_fastcgi.c>
FastCgiServer "D:/AppServ/php/php-cgi.exe" -processes 3
ScriptAlias "/fcgi-bin/" "D:/AppServ/php/"
Action php-fastcgi "/fcgi-bin/php-cgi.exe"
AddType application/x-httpd-php .php
</IfModule>

最後重新啟動 Apache 就可以了。

經測試的結果,在 Virtual Host 也能正常動作。

各項設定簡單說明

  • FastCgiServer :指向 php-cgi.exe 所在位置,詳細說明請參考 http://www.fastcgi.com/mod_fastcgi/docs/mod_fastcgi.html 。
  • ScriptAlias :設定一個別名,這個別名實際指向 php-cgi.exe 所在資料夾路徑。
  • Action :建立一個 action 類型,並指定此類型要由哪個 CGI 來處理。
  • AddType :設定有 php 這個副檔名的檔案,要當成 php 程式來處理 (這個和 module 模式是一樣的) 。

基本上設定這四項就能動了。

目前已知狀況

  1. mod_fastcgi 不能和 php5_module 同時啟用,這樣它只會跑 FastCGI 模式。
  2. 目前我還沒有辦法讓 mod_fastcgi 和 mod_rewrite 配合,在 .htaccess 一開 RewriteEngine 就會有 500 Error 。

參考

以上若有謬誤,還望大家不吝指正。



Posted by jaceju at 樂多Roodo! │17:07 │回應(1)伺服器安裝與設定
樂多分類:網路/3C 工具:編輯本文
Ads by Roodo! 
回應文章
建議改用 fcgid 比較好,配合上比較沒有大問題。
不過因為他有做 wraper ,所以效率上比較差一點。
Posted by tokimrki at 2008年12月1日 15:29