-->
Previous | Table of Contents | Next |
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
Its 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, youll see a number of simultaneous httpd processes running. Whats 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.
Apachelike NCSA 1.4+, Netscapes Web servers, and a couple of other UNIX-based Web serversinstead 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.
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 dont 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, youll 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.
Apache is usually pretty good about giving meaningful error messages, but some are explained in more detail in the following sections.
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 (whats set in src/httpd.h) instead of those relative to the directory youre in. You must give the full path or the path relative to the compiled-in server root.
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 youve specified. Do you have another Web server running? No standard UNIX mechanism is available for determining whats running on what ports; on most systems, the file /etc/services can tell you what the most common daemons are, but its not a complete list. You could also try using the netstat command, with various options such as -a.
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 doesnt actually exist on your system. You might see errors telling you that particular files or directories dont exist. If it looks as though the files are there, make sure that theyre readable by the user IDs that the server runs as (that is, both root and nobody).
Previous | Table of Contents | Next |