安裝 PHP5
首先,從 http://www.php.net/downloads.php 下 載最新的 PHP5.2.9-2 Windows 版本,解壓至 C:/php,把壓縮包中的 php.ini-recommended,更名為 php.ini,然后打開修改幾個選項:error_reporting = E_ALL
display_errors = Onextension_dir = "C:/php/ext"; 動態擴展,可以根據需要去掉 extension 前面的注釋 ; ; 如加載 PDO, MySQLextension=php_pdo.dllextension=php_pdo_mysql.dll; CGI 設置cgi.force_redirect = 1cgi.fix_pathinfo = 1cgi.rfc2616_headers = 1PHP 加載擴展需要注意依賴性,比如 php_exif.dll 需要 php_mbstring.dll,你必須要把 php_mbstring.dll 放在 php_exif.dll 前面才能加載成功。有些擴展依賴額外的 dll 文件,如 PHP 5.0+ ,php_mysqli.dll 依賴 libmysql.dll,而 php_oci8.dll,你則需要安裝 Oracle 8 的客戶端。如果你對這些依賴性不是太了解,可以參考一下安裝包中的 install.txt 文件。
依賴文件的搜索順序:首先是 php.exe 所在的目錄,如果是 ISAPI 模式,那么會搜索 Web Server 的啟動位置,比如 Apache 的 bin 目錄;其次是 Windows PATH 環境變量中的目錄。這里不要復 制任何文件到 Windows 目錄中,有必要的話,可以把 C:/php5 加到 PATH 中,有利于以后 PHP 的升級。
安裝 Nginx
從 v0.7.52 開始,Nginx 開始發布 Windows 版本的 Nginx,你可以在其官方網站上面下載:http://nginx.net我使用的是 0.8.37,下載好以后,解壓釋放文件到 D:/nginx。配置 PHP FastCGI
Nginx 需要和 FastCGI Server 配合才能處理請求,有兩種方式運行 PHP FastCGI Server,一種就是使用 PHP 內置的 FastCGI 管理器:命令行下面執行c:/php/php-cgi.exe -b 127.0.0.1:9000 -c c:/php/php.ini以啟動PHP FastCGI修改 Nginx 的配置文件 d/nginx/conf/nginx.conf,找到 php 相關的部分,修改如下:
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000location ~ /.php$ {root d:/public_html;include php.conf;}root 也就是 $document_root 指的是你的 php scripts 根目錄,設置為你的網站根目錄。在 Windows 下,需要注意的是 root 的路徑,最好使用 "/" 作為路徑分隔符,而不是 Windows 默認的 "/",否則容易出問題,比如,這個路徑:d:/public_html/test,就不會起作用,Nginx 會拋出 500 錯誤,原因是 /test 中 /t 被解析為制表符。當然再加上一個反斜杠轉義也是可以的,如:d://public_html//test。php.conf 是我自己創建的用來保存 php 配置的文件,其實里面只有 3 行命令:
# 連接到本機 9000 端口,這里的端口是指 PHP FastCGI Server 開啟的端口,# 請與 php-cgi.exe 開啟的端口保持一致# 當 Nginx 收到 php 文件的請求時,會自動轉發到 PHP FastCGI Serverfastcgi_pass 127.0.0.1:9000;fastcgi_index index.php;include fastcgi_params;之所以要創建一個獨立的 php.conf 保存配置為了精簡 nginx.conf,當在 nginx 中配置多個虛擬主機時,每個虛擬主機都需要配置 php,那么主配置文件就會變得重復、臃腫。需要修改一下 d:/nginx/conf/fastcgi_params 文件,加入一行:
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;新聞熱點
疑難解答
圖片精選