The Apache Web server is arguably the best and most powerful Web server software available for any operating system. While many learn to edit the configuration files and configure or enable various modules, the bulk of what most people do with Apache is manage the content that Apache serves, with very little attention paid to what Apache itself can do.
Distributions provide initialization scripts for Apache that take the guesswork out of using it. For instance, service httpd start would start the server and an associated stop command would bring it down. These initscripts, while a convenience, largely mask the power of the command they are calling, namely apachectl.
The apachectl command is a rather overlooked program when it comes to working with Apache; however, it can be used to do some very interesting things. For instance, you can debug or test configurations by starting Apache with an alternative configuration file, leaving the working/production configuration untouched until changes can be tested. This can be accomplished with the -f option and the specification of an alternate configuration file:
# apachectl -f /etc/httpd/conf/httpd-testing.conf
This will start an Apache (httpd) process using the httpd-testing.conf file as the primary configuration file rather than the production httpd.conf.
A companion option here would be the -t option which performs a syntax check on configuration files, validating any changes you make. The command will warn if it detects any problems with the configuration file. Use it in conjunction with the -f option to validate in-progress configuration changes on non-default files:
apachectl -t -f /etc/httpd/conf/httpd-testing.conf.
Another useful set of options are those that allow you to examine configuration content without actually opening and scanning configuration files. The apachectl -M command will list all loaded modules, those compiled-in and those that are shared. apachectl -l will display only those static modules that Apache loads; these would be the modules compiled into the httpd binary.
The apachectl -L option displays all available directives that Apache understands, and which module they are associated with. This is a great way to find out what options come from which module, and what they do. For instance:
# apachectl -L
<Directory (core.c) Container for directives affecting resources located in the specified directories
Allowed in *.conf only outside <Directory>, <Files> or <Location>…
The apachectl command also allows you to override directives on the command-line by using the -c option. This can be useful to temporarily test a new site or code. For instance, to override the default ServerLimit directive, use:
# apachectl start -c “ServerLimit 1024”
Other useful directives to override include DocumentRoot and Listen, among others.