-->
Page 163
</CENTER> </FORM> </BODY> </HTML>
Put this file in your htdocs directory. At this point, you are ready to test the server.
If you are running a standalone server, you need to start httpd manually. You do so by entering the following line:
# /sbin/httpd -f /etc/httpd/conf/httpd.conf
Note that I started the standalone server from the root account, indicated by the pound sign (#) at the beginning of the line. You need to start standalone servers by root so that two important events occur:
As you probably guessed, you don't need to start an inetd server. inetd starts httpd every time a request is received in the port assigned to the server. inetd servers make good development platforms because configuration settings are reread every time you send a request.
The Apache server, httpd, has a few command-line options you can use to set some defaults specifying where httpd will read its configuration directives. The Apache httpd executable understands the following options:
httpd [-d ServerRoot] [-f ConfigurationFile] [-x] [-v] [-?]
The -d option overrides the location of the ServerRoot directory. It sets the initial value of the ServerRoot variable (the directory where the Apache server is installed) to whatever path you specify. This default is usually read from the ServerRoot directive in httpd.conf.
The -f flag specifies the location of the main configuration file, conf/httpd.conf. It reads and executes the configuration commands found on ConfigurationFile on startup. If the ConfigurationFile is not an absolute path (doesn't begin with a /), its location is assumed to be relative to the path specified in the ServerRoot directive in httpd.conf. By default, this value is set to ServerRoot/conf/httpd.conf.
Page 164
The -x option is used by the developers of Apache as a debugging aid and should not be used under normal server operation. It runs a single server process that does not create any children.
The -v option prints the development version of the Apache server and terminates the process.
The -? option prints the following usage information for the server:
Usage: httpd [-d directory] [-f file] [-v] -d directory : specify an alternate initial ServerRoot -f file : specify an alternate ServerConfigFile
I have developed a small start script that launches the server with all the command-line settings I use. This script saves me a little typing when I'm trying tasks that require me to start and stop the server. Here's the listing for the start script:
#!/bin/sh /sbin/httpd -f /etc/httpd/conf/httpd.conf
You can create such a script by just typing it into a file (one per script). After you finish entering it, to turn it into executable, type
cd WhereEverYouEnterThem chmod 755 start stop restart
You might want to store the script in a place where it is convenient, such as /usr/local/bin.
The Apache RPM installs a script in /etc/rc3.d named S85httpd that will start the server with the default configuration file.
The server is designed to stop gracefully when it is sent a TERM (terminate) signal. When the server starts, it spawns several children processes; it therefore becomes more difficult to terminate. Apache automatically kills any children processes when the main process is killed. Luckily, the developers of Apache put the process ID of the main process in a file where you can easily obtain the ID. My stop script makes use of the PidFile (/usr/local/etc/httpd/logs/PidFile) file.
The following is the listing for the stop script:
#!/bin/sh #Stop Apache Script kill `cat /var/log/httpd/httpd.pid'
The Apache RPM installs a script named K25httpd in /etc/rc0.d/ that will stop the server.
The server is designed to restart if it receives a -HUP (hang-up) signal. On receiving this type of signal, the server stops and immediately restarts, rereading its configuration files.
Page 165
Here's the listing for the restart script:
#!/bin/sh #Restart Apache Script kill -HUP `cat /var/log/httpd/logs/httpd.pid'
This convenient script automates the process. Any time you modify any of the configuration files, you need to restart the server to enable the changes. Using htrestart makes performing this process easy.
For your convenience, I have provided listings of the various configuration files I talked about in this chapter. You might notice some differences between the files listed here and configuration files of source you download from the Internet. These differences are normal because newer versions of the server might have been released since this printing.
Listing 9.1 shows the server configuration file.
Listing 9.1. conf/httpd.conf.
# This is the main server configuration file. See URL http://www.apache.org/ # for instructions. # Do NOT simply read the instructions in here without understanding # what they do, if you are unsure consult the online docs. You have been # warned. # Originally by Rob McCool # ServerType is either inetd, or standalone. ServerType standalone # If you are running from inetd, go to "ServerAdmin". # Port: The port the standalone listens to. For ports < 1023, you will # need httpd to be run as root initially. Port 80 # HostnameLookups: Log the names of clients or just their IP numbers # e.g. www.apache.org (on) or 204.62.129.132 (off) HostnameLookups on # If you wish httpd to run as a different user or group, you must run # httpd as root initially and it will switch. # User/Group: The name (or #number) of the user/group to run httpd as. # On SCO (ODT 3) use User nouser and Group nogroup User nobody Group #-1
continues