文件下載及官方網站
- VC運行庫Latest下載頁:Latest supported Visual C++ Redistributable downloads | Microsoft Learn
- apache httpd官網:Welcome! - The Apache HTTP Server Project
- 下載頁:Apache VS17 binaries and modules download
- php官網:PHP: Hypertext Preprocessor
- 下載頁:PHP For Windows: Binaries and sources Releases
安裝
VC運行庫
- 從2005~2022一個一個下載安裝,也可以從發現大世界-vc 運行庫-詳情下載打包好的
- 注意版本,VS17 The latest version is?
v14.44.35211.0
PHP
下載后解壓
重命名php.ini配置文件
- 去掉php.ini里面; On windows:下面那行的注釋
- 添加環境變量xxx\php目錄和xxx\php\ext目錄,xxx為路徑
- 打開cmd輸入php -v看到版本號則安裝成功
Apache
- 下載后解壓
- 修改httpd.conf里面Define SRVROOT后面的路勁
- 修改ServerName行并取消注釋
- 以管理員身份打開CMD進入bin目錄
- 鍵入httpd -k install -n apache安裝服務
- 鍵入net start apache啟動服務
- 打開瀏覽器鍵入http://127.0.0.1測試是否安裝成功
FastCGI配置
- 從剛才下載apache下面那里下載mod_fcgid
- 解壓后將mod_fcgid.so復制到apache的modules目錄
- 在apache\conf\extra里面創建httpd-fcgid.conf配置文件
- httpd-fcgid.conf里面鍵入如下內容,PHP路徑填寫自己的
-
<IfModule fcgid_module>
?? ?FcgidInitialEnv PATH "c:/php;C:/WINDOWS/system32;C:/WINDOWS;C:/WINDOWS/System32/Wbem;"
?? ?FcgidInitialEnv SystemRoot "C:/Windows"
?? ?FcgidInitialEnv SystemDrive "C:"
?? ?FcgidInitialEnv TEMP "C:/WINDOWS/Temp"
?? ?FcgidInitialEnv TMP "C:/WINDOWS/Temp"
?? ?FcgidInitialEnv windir "C:/WINDOWS"
?? ?FcgidIOTimeout 64
?? ?FcgidConnectTimeout 16
?? ?FcgidMaxRequestsPerProcess 1000?
?? ?FcgidMaxProcesses 50?
?? ?FcgidMaxRequestLen 8131072?? ?# Location php.ini:
?? ?FcgidInitialEnv PHPRC "d:/server/php"
?? ?FcgidInitialEnv PHP_FCGI_MAX_REQUESTS 1000?? ?<Files ~ "\.php$>"
?? ??? ?Options ExecCGI SymLinksIfOwnerMatch
?? ??? ?AddHandler fcgid-script .php
?? ??? ?FcgidWrapper "d:/server/php/php-cgi.exe" .php
?? ?</Files>
</IfModule>
? - 配置跟下載里面的相同,但多了一條Options ExecCGI SymLinksIfOwnerMatch
- 在apache httpd.conf配置文件中加入如下兩行
- LoadModule fcgid_module modules/mod_fcgid.so
- Include conf/extra/httpd-fcgid.conf?
- CMD中鍵入net stop apache
- CMD中鍵入net start apache
- 重啟apache
- 在apache目錄下的htdocs目錄中新建一個后綴名為.php的文件例如info.php里面鍵入<?php phpinfo();??>
- 瀏覽器訪問此文件驗證配置成功與否
結語
開發角度對比windows下nginx的優缺點
- apache以訪問方式運行不用再去kill nginx了
- 不用再去找隱藏php黑窗口的VBS了
- apache配置對比nginx從個人角度看稍微復雜
參考
- PHP: 在Windows系統上安裝 Apache 2.x - Manual
- Setting up PHP with FastCGI on Windows using Apache