Networking / Beginners

Configuring the Apache Server

Normally, at this point in the discussion of server software, I say something like this: "Installation is only the beginning. Now you must configure the software." That is not really the case for the Apache web server running on Linux. It is configured and will run with only a little input from you. You edit the httpd.conf file to set the web administrator's e-mail address in ServerAdmin and the server's hostname in ServerName. Beyond that, the httpd configuration provided with a Linux distribution should be adequate for that version of Linux.

The httpd.conf file is stored in the /etc/httpd/conf directory on Red Hat systems. Another operating system may place the configuration file in a different directory. To find where it is located on your system, look in the script that was used to start httpd. The location of the httpd.conf file is defined there. The locations of other files used by httpd are defined in httpd.conf. Another very simple way to locate the file is with the find command:

# find / -name httpd.conf -print

This command tells find to search every directory from the root (/) on down for a file named httpd.conf, and to print out the result of the search. Use find any time you need to locate a file.

After locating httpd.conf, use an editor to put valid ServerAdmin and ServerName values into the configuration. In the Red Hat Linux 7.2 example, ServerAdmin is delivered with this default value:

ServerAdmin root@localhost

The e-mail address of root@localhost is a valid address, but it is not one we would want to advertise to remote users. We change ServerAdmin to

ServerAdmin webmaster@www.example.org

The delivered value for ServerName is:

#ServerName localhost

In this case, ServerName is commented out. We remove the hash mark (#) to activate the line, and we change ServerName to

ServerName www.example.org

We saw that when our Apache server is running, it is serving out data. Of course, the data 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 Red Hat server gets web pages from the /var/www/html directory, as you can see by checking the value for DocumentRoot in the httpd.conf file:

$ grep '^DocumentRoot' httpd.conf
DocumentRoot "/var/www/html"
$ ls /var/www/html
index.html manual poweredby.png

The /var/www/html directory contains two files and one directory. The poweredby.png file is the "Powered by Red Hat Linux" graphic seen at the bottom of the web page. The index.html file is the HTML document that creates the 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. The manual directory contains Apache documentation. It can be viewed by following the documentation link that is near the bottom of the default web page.

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 out your data. Alternatively, you can edit the httpd.conf file to change the value in the DocumentRoot directive to point to the directory in which you store your data. The choice is yours. Either way, you need to create HyperText Markup Language (HTML) documents for the web server to display.

After the minimal changes are made to the httpd.conf file, the server can be restarted. The easiest way to do this on a Red Hat system is to run the /etc/init.d/httpd script file with the argument restart.

[Previous] [Contents] [Next]