修改了apache httpd.conf文件之后,怎么樣驗證其語法是否正確呢?
當然,我們可以重新啟動apache服務(wù)器,但這樣一來,如果萬一存在錯誤,apache服務(wù)器將不能正常啟動,也不能提供正常服務(wù)。
所以我們在修改了apache的配置文件之后,最好對其驗證,確保了其語法上正確無誤之后,才重新啟動apache服務(wù)器。
apache httpd.conf語法驗證可以通過下面的命令來驗證。
Windows環(huán)境:
httpd -t
或者:
httpd.exe -w -t -f “C:Apache2.2confhttpd.conf” -d “C:Apache2.2.”
Linux環(huán)境:
apachectl configtest
或
apache2ctl configtest
SUSE等系統(tǒng)的apache2,可能為apache2ctl命令。
如果你不能確認自己的apache服務(wù)器到底使用哪個命令,你可以使用
find / -name “apachectl”
或者
find / -name “apache2ctl”
來查找一下。
如果正確無誤,會顯示Syntax OK信息。
sudo /Applications/MAMP/Library/bin/apachectl configtest
Syntax OK
如果存在錯誤,則會顯示出錯的行號以及錯誤信息,如下:
sudo /Applications/MAMP/Library/bin/apachectl configtest
Syntax error on line 623 of /Applications/MAMP/conf/apache/httpd.conf:
CustomLog takes two or three arguments, a file name, a custom log format string or format name, and an optional “env=” clause (see docs)