Share!
Recommended course:

Complete Apache HTTP Server Course

It's a pain to get a configuration error when restarting your Apache service and the service just wouldn't start; even more so in a production environment. It's always a good idea to test the validity of your newly updated Apache config file before restarting the service.

You can use both apachectl and httpd to test your Apache configuration.

Test Apache configuration using httpd

$ httpd -t
AH00112: Warning: DocumentRoot [/usr/docs/dummy-host.example.com] does not exist
AH00112: Warning: DocumentRoot [/usr/docs/dummy-host2.example.com] does not exist
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1. Set the 'ServerName' directive globally to suppress this message
Syntax OK

Test Apache configuration using apachectl

Different platform might use different binary names such as apache, apache2 or apache2ctl

$ apachectl configtest
AH00112: Warning: DocumentRoot [/usr/docs/dummy-host.example.com] does not exist
AH00112: Warning: DocumentRoot [/usr/docs/dummy-host2.example.com] does not exist
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1. Set the 'ServerName' directive globally to suppress this message
Syntax OK

What happens is that the programs will try to parse the configuration files without implementing any of your changes. Once you get Syntax OK at the end of the output and are satisfied with all the warnings (if any), you could confidently restart your Apache service.