Test Apache Web Server Configuration for Syntax Errors Before Restarting
So you made those changes to your Apache Web Server configuration files and went on to start
, restart
or reload
the server so that the shiny new changes are picked up but bam! You made some minor syntax error, server went down crashing and now you have a bad downtime 🙁
Well if you made any changes to the httpd configuration, make it a habit to always test your config for syntax errors. Running syntax checks is super easy with the apachectl
program that ships with your Apache web server installation and acts as a frontend to the httpd server. This is all you gotta do:
# apachectl configtest
Syntax OK
If all the syntax parsing tests run fine then the program exits with a 0
return code, meaning all is well. In that case you’ll see Syntax OK
printed to your standard output.
But what if there’s an actual error, what does it look like ? Well let’s quickly emulate that. I change ServerName
to ServerNameMisspelled
and then a config test would yield this:
# apachectl configtest
AH00526: Syntax error on line 9 of /etc/apache2/sites-enabled/codingshower.conf:
Invalid command 'ServerNameMisspelled', perhaps misspelled or defined by a module not included in the server configuration
Action 'configtest' failed.
The Apache error log may have more information.
So next time before you want httpd to pick up your brand new configuration changes, run the syntax parsing tests first to ensure you didn’t make silly syntactical errors.
Note: apachectl configtest
is equivalent to apachectl -t
.
Note 2: Of course this tool won’t help with logical mistakes like virtual host mismatch, listening on random ports, logging errors in access logs and vice-versa, so on and so forth.