The Question :
I’m looking for a command that checks the validity of the config files in Apache server on both Debian and RHEL distros. I need to do this prior to restart, so there will be no downtime.
The Answer 1
The Answer 2
Another way is
httpd -t. Therefore, it’s available in Windows-version of Apache. Check http://httpd.apache.org/docs/2.4/programs/httpd.html
The Answer 3
apachectl configtest is the correct answer.
Unfortunately I’ve got a windows installation where apachectl is missing.
httpd also helps.
The Answer 4
The Apache config test (
apachectl configtest, or its equivalents) only tests the config file (and the files it recursively includes) for valid syntax. However, the original question asked for preventing downtime. Even when
apachectl configtest does not return an error, an actual restart may still fail, causing downtime.
Common causes for such failures include missing or inaccessible SSL certificates, missing directories for log files or a missing website root directory. Often, such errors are caused by removing a vhost’s directory without removing the vhost Apache config file. It is highly recommended to use a tool like puppet or ansible to prevent such inconsistencies.
Seeing that this question is the number one hit when googling “apache config lint” I thought I’d mention this little detail…
The Answer 5
What I usually do is
apache2ctl -t && apache2ctl graceful