If you want to check that Apache’s configuration is valid without actually starting the server, you can do so by passing the server executable the -t option. The following uses a Unix installation path as an example:
$ /usr/local/apache/bin/httpd -t
This will report any problems with the configuration or return a “Syntax OK” message if all is well. If you included any directories into the configuration, then you’ll also get a list of the configuration files Apache found and processed. The document roots of the primary server and any virtual hosts you have created are also checked, and a warning is issued in each case if the associated directory is not present. You can disable this check by using the -T option, which is in all other respects identical to -t:
$ /usr/local/apache/bin/httpd -T
You can also use apachectl, which will test the configuration inclusive of document root checks using the configtest mode:
$ apachectl configtest
To test a Windows service configuration, use the -t or -T options in conjunction with -n:
c:\> apache -n Apache2 -t
This is just a convenience wrapper around a call to the server executable using -t; in a default installation, it’s identical to the first command given previously. If you want to change it to -T or add a corresponding configtestnoroot mode, then it’s simple to adapt apachectl accordingly.
Windows installations performed by the installer additionally create a menu item to test the configuration.
Getting the Server Status from the Command Line
If you have mod_status configured into the server, you can also test it from the command line using apachectl and the status or fullstatus options. These extract a status report from the server:
$ apachectl status
or for a full status report (note that this option is called extendedstatus in earlier versions of apachectl):
$ apachectl fullstatus
Nice though this seems, it’s really just a wrapper around a conventional HTTP request that you might equally have made with a browser or a telnet command. As such, it will work only if apachectl is configured to point to a URL that will return a status page. If you have modified how and where a status page is delivered, you’ll need to modify apachectl. In addition, apachectl uses an external program, by default the text-only Lynx browser, to actually do the work, so the fullstatus option is actually equivalent (on a default Unix installation where the port is set to 80 with Listen or Port) to the following:
lynx -dump http://localhost:80/server-status
This is actually what the default Apache configuration responds to, so out of the box it should work (so long as you have Lynx actually installed, of course). In addition, if you build Apache with a different initial configuration—for instance, a different default listening port or a different name for the server binary—then apachectl will be installed with that port number or server name preset in the program.
It’s entirely possible and actually easy to extend apachectl to produce other kinds of test reports, for instance, adding the apachectl info command to retrieve the information page produced by mod_info. You just need to add a clause for info and maybe add an INFOURL constant at the top of the program. After viewing the apachectl script in an editor, the changes to make should be self-evident. Given time, it’s possible and quite appealing to turn apachectl into a custom Web server tuning and monitoring tool.
This chapter is from Pro Apache by Peter Wainwright. (Apress, 2004, ISBN: 1590593006). Check it out at your favorite bookstore today. Buy this book now.