Starting Apache - Apache HTTP Server Version 2.4 (original) (raw)

On Windows, Apache is normally run as a service. For details, see Running Apache as a Service.

On Unix, the [httpd](./programs/httpd.html) program is run as a daemon that executes continuously in the background to handle requests. This document describes how to invoke [httpd](./programs/httpd.html).

top

How Apache Starts

If the [Listen](./mod/mpm%5Fcommon.html#listen) specified in the configuration file is default of 80 (or any other port below 1024), then it is necessary to have root privileges in order to start apache, so that it can bind to this privileged port. Once the server has started and performed a few preliminary activities such as opening its log files, it will launch several_child_ processes which do the work of listening for and answering requests from clients. The main httpd process continues to run as the root user, but the child processes run as a less privileged user. This is controlled by the selectedMulti-Processing Module.

The recommended method of invoking the [httpd](./programs/httpd.html) executable is to use the [apachectl](./programs/apachectl.html) control script. This script sets certain environment variables that are necessary for[httpd](./programs/httpd.html) to function correctly under some operating systems, and then invokes the [httpd](./programs/httpd.html) binary.[apachectl](./programs/apachectl.html) will pass through any command line arguments, so any [httpd](./programs/httpd.html) options may also be used with[apachectl](./programs/apachectl.html). You may also directly edit the[apachectl](./programs/apachectl.html) script by changing the HTTPD variable near the top to specify the correct location of the[httpd](./programs/httpd.html) binary and any command-line arguments that you wish to be always present.

The first thing that [httpd](./programs/httpd.html) does when it is invoked is to locate and read the configuration file httpd.conf. The location of this file is set at compile-time, but it is possible to specify its location at run time using the -f command-line option as in

/usr/local/apache2/bin/apachectl -f /usr/local/apache2/conf/httpd.conf

If all goes well during startup, the server will detach from the terminal and the command prompt will return almost immediately. This indicates that the server is up and running. You can then use your browser to connect to the server and view the test page in the [DocumentRoot](./mod/core.html#documentroot) directory.

top

Errors During Start-up

If Apache suffers a fatal problem during startup, it will write a message describing the problem either to the console or to the [ErrorLog](./mod/core.html#errorlog) before exiting. One of the most common error messages is "Unable to bind to Port ...". This message is usually caused by either:

For further trouble-shooting instructions, consult the Apache FAQ.

top

Starting at Boot-Time

If you want your server to continue running after a system reboot, you should add a call to [apachectl](./programs/apachectl.html) to your system startup files (typically rc.local or a file in an rc.N directory). This will start Apache as root. Before doing this ensure that your server is properly configured for security and access restrictions.

The [apachectl](./programs/apachectl.html) script is designed to act like a standard SysV init script; it can take the argumentsstart, restart, and stop and translate them into the appropriate signals to[httpd](./programs/httpd.html). So you can often simply link[apachectl](./programs/apachectl.html) into the appropriate init directory. But be sure to check the exact requirements of your system.

top

Comments

Notice:
This is not a Q&A section. Comments placed here should be pointed towards suggestions on improving the documentation or server, and may be removed by our moderators if they are either implemented or considered invalid/off-topic. Questions on how to manage the Apache HTTP Server should be directed at either our IRC channel, #httpd, on Libera.chat, or sent to our mailing lists.