【現象】
D:\apache\Apache24\bin>httpd -k install
Installing the 'Apache2.4' service
The 'Apache2.4' service is successfully installed.
Testing httpd.conf....
Errors reported here must be corrected before the service can be started.
httpd: Syntax error on line 40 of D:/apache/Apache24/conf/httpd.conf: ServerRoot must be a valid directory
【原因】
httpd.conf里面配置的ServerRoot路徑跟實際路徑不一致,導致路徑無效。
【解決步驟一】
打開Apache2.4.16解壓文件下的bin文件里面的httpd.conf
本文為:D:\apache\Apache24\conf\httpd.conf
【解決步驟二】
打開httpd.conf后,搜索Define SRVROOT(只有一處),將其后面的雙引號里面的路徑改為Apache的實際解壓路徑后保存即可,本文為D:\apache\Apache24
【解決步驟三】
運行CMD,cd到apache\Apache24\bin執行httpd -k install,不再報錯ServerRoot must be a valid directory,成功安裝apache服務。
D:\apache\Apache24\bin>httpd -k install
Installing the 'Apache2.4' service
The 'Apache2.4' service is successfully installed.
Testing httpd.conf....
Errors reported here must be corrected before the service can be started.
D:\apache\Apache24\bin>httpd -v
【解決步驟四】
啟動apache服務並且測試apache服務
1、運行cmd后執行net start Apache2.4;
D:\apache\Apache24\bin>net start Apache2.4
Apache2.4 服務正在啟動 ..
Apache2.4 服務已經啟動成功。
2、瀏覽器輸入:http://localhost/