修改了apache httpd.conf文件之后,怎么樣驗(yàn)證其語法是否正確呢?
當(dāng)然,我們可以重新啟動(dòng)apache服務(wù)器,但這樣一來,如果萬一存在錯(cuò)誤,apache服務(wù)器將不能正常啟動(dòng),也不能提供正常服務(wù)。
所以我們?cè)谛薷牧薬pache的配置文件之后,最好對(duì)其驗(yàn)證,確保了其語法上正確無誤之后,才重新啟動(dòng)apache服務(wù)器。
apache httpd.conf語法驗(yàn)證可以通過下面的命令來驗(yàn)證。
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命令。
如果你不能確認(rèn)自己的apache服務(wù)器到底使用哪個(gè)命令,你可以使用
find / -name “apachectl”
或者
find / -name “apache2ctl”
來查找一下。
如果正確無誤,會(huì)顯示Syntax OK信息。
sudo /Applications/MAMP/Library/bin/apachectl configtest
Syntax OK
如果存在錯(cuò)誤,則會(huì)顯示出錯(cuò)的行號(hào)以及錯(cuò)誤信息,如下:
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)