Apache: Starting, Stopping, and Restarting
In this chapter:
- apachectl
- httpd
- Starting on System Startup
- Microsoft Windows
There are two kinds of fool. One says, "This is old, and therefore good." And one says "This is new, and therefore better."
The Shockwave RiderJohn Brunner
Now that your server is installed, you need to get it running. Don't be concerned that we've devoted an entire chapter to this. It really is simple. But, there are some additional things that you'll want to know about starting, stopping, and restarting your server.
apachectl
Most of the time, you want to use apachectl to start and stop your server. apachectl is a handy little script designed to take the grunt work out of starting, stopping, and restarting Apache.
You'll find apachectl in the bin directory of wherever you installed Perl. You might want to copy, or symlink, it into /usr/local/bin, or somewhere else in your path, because you might need it frequently, at least while you're learning about Apache.
apachectl can be run with one of eight different options.
A complete listing of the options can be obtained by running apachectl with the help option:
% apachectl help usage: /usr/local/bin/apachectl (start|stop|restart| fullstatus|status|graceful|configtest|help) start - start httpd stop - stop httpd restart - restart httpd if running by sending a SIGHUP or start if not running fullstatus - dump a full status screen; requires lynx and mod_status enabled status - dump a short status screen; requires lynx and mod_status enabled graceful - do a graceful restart by sending a SIGUSR1 or start if not running configtest - do a configuration syntax test help - this screen
These options are, for the most part, self-explanatory.
status and fullstatus will be covered in more detail in Chapter 14, "Handlers and Filters," when we discuss mod_status. configtest will be discussed in more detail when we discuss configuration directives in Chapter 4, "Configuration Directives."
The start, stop, restart, and graceful options are of particular interest to this section of the book. The first two do exactly what you would expect. restart does what you would expect also, but it's important to know that it also rereads the configuration files, so if any changes have been made, those changes go into effect on a restart. graceful is useful because any connections to the server that are currently active will be completed before the server is restarted. This is important because it means that nobody's connection will be unceremoniously dropped in the middle of receiving a file, therefore, the perceived downtime of the server will be lessened.
For both restart and graceful, if there is a syntax error in the configuration file(s), Apache will not successfully restart. However, Apache is smart enough to check the syntax of the configuration files before shutting down, rather than waiting until it is time to start back up. So, if there is a problem with the configuration files, Apache won't even shut down in the first place. This was not true with earlier versions, where a restart would occasionally leave you with your server down, if you did not check your configuration syntax before attempting the restart.