Apache Tip #2: Use Configtest to Try Configurations Before Using

The Apache configuration file is deceptively simple. It is just a plain text file filled with mostly plain words. It does not require a registry, hex editing, or any other form of complex configuration. Still, with one misstep, one typo, or one incorrectly placed directive, you can bring your web server to its knees.

Rather than run the risk of causing a server-wide outage every time you change a configuration setting in Apache, you can use a little tool called configtest. It is one of the many options available for the “apachectl” command. Using it you can scan your httpd.conf file to make sure it will work properly the next time you restart Apache. If there are any problems, configtest will output the errors for you.

For example, to test your current httpd.conf settings, you would type the following from the command line:

apachectl configtest

If all goes well, it will give you this output:

Syntax OK

When things do not go well, configtest will display an error message like this:

Syntax error on line 33 of /usr/local/apache/conf/httpd.conf:

Invalid command ‘sserversignature’, perhaps misspelled or defined by a module not included in the server configuration

You can then go back to your httpd.conf file and edit the line mentioned in the error message. In this way, you can repeatedly test your configuration until it passes with “Syntax OK”. Then, you will know that it is safe to actually restart Apache and let your configuration changes take effect.