Starting Apache for the First Time
Before you start Apache, you should verify that the minimal set of information is present in the Apache configuration file, httpd.conf. The following sections describe the basic information needed to configure Apache and to start the server.
Check Your Configuration File
You can edit the Apache httpd.conf file with your favorite text editor. In Linux/UNIX and Mac OS X, this probably means vi or emacs. In Windows, you can use Notepad or WordPad. You must remember to save the configuration file in plain text, which is the only format Apache will understand.
There are only two parameters that you might need to change to enable you to start Apache for the first time: the name of the server and the address and port to which it is listening. The name of the server is the one Apache will use when it needs to refer to itself (for example, when redirecting requests).
Apache can usually figure out its server name from the IP address of the machine, but this is not always the case. If the server does not have a valid DNS entry, you might need to specify one of the IP addresses of the machine. If the server is not connected to a network (you might want to test Apache on a standalone machine), you can use the value 127.0.0.1, which is the loopback address. The default port value is 80. You might need to change this value if there is already a server running in the machine at port 80, or if you do not have administrator permissions—on Linux/UNIX and Mac OS X systems, only the root user can bind to privileged ports (those with port numbers lower than 1024).
You can change both the listening address and the port values with the Listen directive. The Listen directive takes either a port number or an IP address and a port, separated by a colon. If only the port is specified, Apache will listen on that port at all available IP addresses in the machine. If an additional IP address is provided, Apache will listen at only that address and port combination. For example, Listen 80 tells Apache to listen for requests at all IP addresses on port 80. Listen 10.0.0.1:443 tells Apache to listen only at 10.0.0.1 on port 443.
The ServerName directive enables you to define the name the server will report in any self-referencing URLs. The directive accepts a DNS name and an optional port, separated by a colon. Make sure that ServerName has a valid value. Otherwise, the server will not function properly; for example, it will issue incorrect redirects.
On Linux/UNIX and Mac OS X platforms, you can use the User and Group directives to specify which user and group IDs the server will run as. The nobody user is a good choice for most platforms. However, there are problems in the HP-UX platform with this user ID, so you must create and use a different user ID, such as www.
Starting Apache
To start Apache on Linux/UNIX, change to the directory containing the apachectl script and execute the following command:
# /usr/local/apache2/bin/apachectl start
Mac OS X users can type the following at the prompt:
# /usr/sbin/httpd
To manually start Apache on Windows, click the Start Apache in Console link in the Control Apache Server section, within the Apache HTTP Server 2.0.55 program group in the Start menu. If you installed Apache as a service, you must start the Apache service instead.
If everything goes well, you can access Apache using a browser. A default installation page will be displayed, such as the one shown in Figure 3.5. If you cannot start the web server or an error page appears instead, please consult the "Troubleshooting" section that follows. Make sure that you are accessing Apache in one of the ports specified in the Listen directive—usually port 80 or 8080.
Figure 3.5 Apache default installation page.