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.
Check: http://httpd.apache.org/docs/2.2/programs/apachectl.html
apachectl configtest
-
I am getting this message running the above command
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
– Ciasto piekarz Sep 15 '16 at 16:18 -
2Add a line "ServerName whateveryoulike" to your apache config. Replace whateveryoulike with what ever you like to name your server. – Pit Sep 26 '16 at 6:48
-
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
-
1Oddly, on Ubuntu, when I run
apachectl configtest
I getSyntax OK
, but when I runapache2 -t
I getAH00526: Syntax error on line 74 of /etc/apache2/apache2.conf
(among other errors) – Buttle Butkus Dec 8 '18 at 2:02
apachectl configtest
is the correct answer.
Unfortunately I've got a windows installation where apachectl is missing.
Here calling httpd
also helps.
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...
-
-
That would require a script, that parses the apache config and implements the missing checks. I'm not aware of any freely available scripts that does so. – BertD Sep 22 '20 at 12:26