home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


Book HomeTCP/IP Network AdministrationSearch this book

11.2. Configuring the Apache Server

Apache configuration traditionally involves three files:

httpd.conf

This is the primary configuration file. It traditionally contains configuration settings for the HTTP protocol and for the operation of the server. This file is processed first.

srm.conf

This file traditionally contains configuration settings to help the server respond to client requests. The settings include how to handle different MIME types, how to format output, and the location of HTTP documents and Common Gateway Interface (CGI) scripts. This file is processed second.

access.conf

This file traditionally defines access control for the server and the information the server provides. This file is processed last.

All three files have a similar structure: they are all written as ASCII text files, comments begin with a #, and the files are well commented. Most of the directives in the files are written in the form of an option followed by a value.

We say that these three files traditionally handle Apache configuration, but common practice today has diverged from that approach. There is overlap in the function of the three files. You may think you know where a certain value should be set, only to be surprised to find it in another file. In fact, any Apache configuration directive can be used in any of the configuration files -- the traditional division of the files into server, data, and security functions was essentially arbitrary. Some administrators still follow tradition, but it is most common for the entire configuration to be defined in the httpd.conf file. This is the recommended approach, and the one we use in this chapter.

Different systems put the httpd.conf file in different directories. On a Solaris system, the file is stored in the /etc/apache directory; on a Red Hat system, it is found in the /etc/httpd/conf directory; and on Caldera systems, in the /etc/httpd/apache/conf directory. The Apache manpage should tell you where httpd.conf is located on your system; if it doesn't, look in the script that starts httpd at boot time. The location of the httpd.conf file will either be defined by a script variable or by the -f argument on the httpd command line. Of course, a very simple way to locate the file is with the find command, as in this Caldera Linux example:

# find / -name httpd.conf -print
/etc/httpd/apache/conf/httpd.conf

Once you find httpd.conf, customize it for your system. The Apache configuration file is large and complex; however, it is preconfigured, so your server will run with only a little input from you. Edit the httpd.conf file to set the web administrator's email address in ServerAdmin and the server's hostname in ServerName. With those small changes, the httpd configuration provided with your Unix system will probably be ready to run. Let's look at a Solaris 8 example.

11.2.1. Configuring Apache on Solaris

The first step to configure Apache on a Solaris system is to copy the file httpd.conf-example to httpd.conf:

# cd /etc/apache
# cp httpd.conf-example httpd.conf

Use an editor to put valid ServerAdmin and ServerName values into the configuration. In the Solaris example, we change ServerAdmin from:

ServerAdmin you@your.address

to:

ServerAdmin webmaster@www.wrotethebook.com

We change ServerName from:

#ServerName new.host.name

to:

ServerName www.wrotethebook.com

Once these minimal changes are made, the server can be started. The easiest way to do this on a Solaris system is to run the /etc/init.d/apache script file. The script accepts three possible arguments: start, restart, and stop. Since httpd is not yet running, there is no daemon to stop or restart, so we use the start command:

# /etc/init.d/apache start
httpd starting.
# ps -ef | grep '/httpd'
  nobody   474   473  0 12:57:27 ?        0:00 /usr/apache/bin/httpd
  nobody   475   473  0 12:57:27 ?        0:00 /usr/apache/bin/httpd
  nobody   476   473  0 12:57:27 ?        0:00 /usr/apache/bin/httpd
    root   473     1  0 12:57:26 ?        0:00 /usr/apache/bin/httpd
  nobody   477   473  0 12:57:27 ?        0:00 /usr/apache/bin/httpd
  nobody   478   473  0 12:57:27 ?        0:00 /usr/apache/bin/httpd
    root   501   358  0 13:10:04 pts/2    0:00 grep /httpd

After running the apache startup script, run ps to verify that the httpd daemon is running.[126] In this example, several copies of the daemon are running, just as we saw earlier in the Linux example. This group of daemons is called the swarm, and we'll examine the Apache configuration directives that control the size of the swarm later.

[126]The DynaWeb (dwhttpd) daemon, which is used to display the AnswerBook, may also appear in the ps list on Solaris systems that run an AnswerBook2 server.

Now that the daemons are running, run Netscape. Enter "localhost" in the location box, and you should see something like Figure 11-3.

Figure 11-3

Figure 11-3. Default web page on a Solaris server

Our Solaris Apache server is now up, running, and serving data. Of course, this is not really the data we want to serve our clients. There are two solutions to this problem: either put the correct data in the directory that the server is using, or configure the server to use the directory in which the correct data is located.

The DocumentRoot directive points the server to the directory that contains web page information. By default, the Solaris server gets web pages from the /var/apache/htdocs directory, as you can see by checking the value for DocumentRoot in the httpd.conf file:

# grep '^DocumentRoot' httpd.conf
DocumentRoot "/var/apache/htdocs"
# ls /var/apache/htdocs
apache_pb.gif  index.html

The /var/apache/htdocs directory contains only two files. The GIF file is the Apache feather graphic seen at the bottom of the web page in Figure 11-3. The index.html file is the HTML document that creates this web page. By default, Apache looks for a file named index.html and uses it as the home page if a specific page has not been requested. You can put your own index.html file in this directory, along with any other supporting files and directories you need, and Apache will start serving your data. Alternately, you can edit the httpd.conf file to change the value in the DocumentRoot directive to point to the directory where you store your data. The choice is yours. Either way, you need to create HTML documents for the web server to display.

Although the Solaris server can run after modifying only two or three configuration directives, you still need to understand the full range of Apache configuration. Given the importance of web services for most networks, Apache is too essential for you to ignore. To properly debug a misconfigured web server, you need to understand the entire httpd.conf file. The following sections examine this file in detail.



Library Navigation Links

Copyright © 2002 O'Reilly & Associates. All rights reserved.