Apache-Related Commands

The Apache distribution includes several executables. This section covers only the server binary and related scripts. Hour 15, "Restricting Access to Your Applications," and Hour 22, "Apache Performance Tuning and Virtual Hosting," cover additional utilities included with the Apache distribution.

Apache Server Binary

The Apache executable is named httpd in Linux/Unix and apache.exe in Windows. It accepts several command-line options, which are described in Table 2.1. You can get a complete listing of options by typing /usr/local/apache2/bin/httpd -h on Linux/Unix, or by typing apache.exe -h from a command prompt on Windows.

Table 2.1. httpd Options




Allows you to pass a parameter that can be used for <IfDefine> section processing


Lists compiled-in modules


Shows version number and server compilation time


Allows you to pass the location of httpd.conf if it is different from the compiletime default

After Apache is running, you can use the kill command on Linux/Unix to send signals to the parent Apache process. Signals provide a mechanism to send commands to a process. To send a signal, execute the following command:

#> kill -SIGNAL pid

where pid is the process ID and SIGNAL is one of the following:

  • HUP? Stop the server

  • USR1 or WINCH? Graceful restart; which signal to use depends on the underlying operating system

  • SIGHUP? Restart

If you make some changes to the configuration files and you want them to take effect, you must signal Apache that the configuration has changed. You can do this by stopping and starting the server or by sending a restart signal. This tells Apache to reread its configuration.

A normal restart can result in a momentary pause in service. A graceful restart takes a different approach. Each thread or process serving a client will keep processing the current request, but when it is finished, it will be killed and replaced by a new thread or process with the new configuration. This allows seamless operation of the Web server with no downtime.

On Windows, you can signal Apache using the apache.exe executable:

  • apache.exe -k restart? Tells Apache to restart

  • apache.exe -k graceful? Tells Apache to do a graceful restart

  • apache.exe -k stop? Tells Apache to stop

You can access shortcuts to these commands in the Start menu entries that the Apache installer created. If you installed Apache as a service, you can start or stop Apache by using the Windows service interface: In Control Panel, select Administrative Tasks and then click on the Services icon.

Apache Control Script

Although it is possible to control Apache on Linux/Unix using the httpd binary, it is recommended that you use the apachectl tool. The apachectl support program wraps common functionality in an easy-to-use script. To use apachectl, type

#> ./apachectl command

where command is stop, start, restart, or graceful. You can also edit the contents of the apachectl script to add extra command-line options.

Some OS distributions provide you with additional scripts to control Apache; please check the documentation included with your distribution.

    Part III: Getting Involved with the Code