142

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.

migrated from stackoverflow.com Feb 7 '11 at 13:30

This question came from our site for professional and enthusiast programmers.

206

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
  • Add 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
  • 1
    might require sudo ? – Miguel Mar 29 '17 at 10:29
35

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

  • Oddly, on Ubuntu, when I run apachectl configtest I get Syntax OK, but when I run apache2 -t I get AH00526: Syntax error on line 74 of /etc/apache2/apache2.conf (among other errors) – Buttle Butkus Dec 8 '18 at 2:02
6

apachectl configtest is the correct answer. Unfortunately I've got a windows installation where apachectl is missing. Here calling httpd also helps.

0

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...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.