-->
Previous Table of Contents Next


Starting Up Apache

To start Apache, simply run the binary you compiled earlier (or your precompiled binary) with the -f flag pointing to the httpd.conf file also created earlier, as in this example:


/usr/local/apache/src/httpd -f /usr/local/apache/conf/httpd.conf

The following sample init script also activates the Apache Web server. The Red Hat distribution automatically installs this script if you select to install the Web server.


#!/bin/sh

#

# Startup script for the Apache Web Server

#

# chkconfig: 345 85 15

# description: Apache is a World Wide Web server. It is used to serve \

# HTML files and CGI.

#

#



# Source function library.

. /etc/rc.d/init.d/functions



# See how we were called.

case "$1" in

  start)

        echo -n "Starting httpd: "

        daemon httpd

        echo

        touch /var/lock/subsys/httpd

        ;;

  stop)

        echo -n "Shutting down http: "

        kill ‘cat /var/run/httpd.pid’

        echo httpd

        rm -f /var/lock/subsys/httpd

        rm -f /var/run/httpd.pid

        ;;

  status)

        status httpd

        ;;

  restart)

        $0 stop

        $0 start

        ;;

  *)

        echo "Usage: httpd.init {start|stop|restart|status}"

        exit 1

esac



exit 0

It’s probably a good idea at this point to use the ps command to see if httpd is running. Typically, something like ps -aux | grep will suffice. To your surprise, you’ll see a number of simultaneous httpd processes running. What’s going on?

The first Web servers, such as CERN and NCSA, used the model of one main Web server cloning itself with every single request that came in. The clone would respond to the request, while the original server returned to listening to the port for another request. Although certainly a simple and robust design, the act of cloning (or, in UNIX terms, forking) was an expensive operation under UNIX, so loads above a couple hits per second were quite punishing even on the nicest hardware. It was also difficult to implement any sort of throttling, which reduced the amount of cloning that took place. When the number of clones was very high, it was hard for the original server to know how many clones were still around. Thus, servers had no easy way to refuse or delay connections based on a lack of resources.

Apache—like NCSA 1.4+, Netscape’s Web servers, and a couple of other UNIX-based Web servers—instead uses the model of a group of persistent children running in parallel. The children are coordinated by a parent process, which can tell how many children are alive, spawn new children (if necessary), and even terminate old children if there are many idle ones, depending on the situation. (Parent and child are the actual UNIX terms.)

Back to the server. Fire up your Web browser and point it to your local server. (Use the usual http:// format and append the ServerName parameter you defined in the httpd.conf file.) Did it work? If all went well, you should be able to see a directory index listing of everything in the document root directory, or if an index.html is in that directory, you would see the contents of that file.

Table 35.1 shows other command-line options.

Table 35.1 Command-Line Options for httpd

Option Result

-d serverroot Sets the initial value for ServerRoot.
-X Runs the server in single-process mode. (This is useful for debugging purposes, but don’t run the server in this mode for serving content to the outside world.)
-v Prints the version of the server, and then exits.
-? Prints the list of available command-line arguments to Apache.

After you check to make sure that Apache starts up correctly, you’ll probably want to add the startup command to your system boot scripts so that Apache will start automatically when the system boots. A typical location for the startup command would be in the file /etc/rc.d/rc.local.

Debugging the Server Startup Process

Apache is usually pretty good about giving meaningful error messages, but some are explained in more detail in the following sections.

Open File Error Messages


httpd: could not open document config file .....

fopen: No such file or directory

These open file error messages are usually the result of giving just a relative path to the -f argument, so Apache looks for the file(s) relative to the compiled-in server root (what’s set in src/httpd.h) instead of those relative to the directory you’re in. You must give the full path or the path relative to the compiled-in server root.

Port and Bind Error Messages


httpd: could not bind to port [X]

bind: Operation not permitted

The port and bind error messages are most likely caused by attempting to run the server on a port below 1024 without launching it as “root.” Most UNIX operating systems, including Linux, prevent people without root access from trying to launch any type of server on a port less than 1024. If you launch the server as root, the error message should disappear.


httpd: could not bind to port

bind: Address already in use

These port and bind error messages mean that something is already running on your machine at the port you’ve specified. Do you have another Web server running? No standard UNIX mechanism is available for determining what’s running on what ports; on most systems, the file /etc/services can tell you what the most common daemons are, but it’s not a complete list. You could also try using the netstat command, with various options such as -a.

Bad User or Group Name Messages


httpd: bad user name ....

httpd: bad group name ....

Bad user or group name error messages mean that the user or the group you specified in httpd.conf doesn’t actually exist on your system. You might see errors telling you that particular files or directories don’t exist. If it looks as though the files are there, make sure that they’re readable by the user IDs that the server runs as (that is, both root and nobody).


Previous Table of Contents Next