"Linux Gazette...making Linux just a little more fun! "

Setting Up the Apache Web Server Under Linux

by Andy Kahn, kahn@cs.ucla.edu

This article is basically a summary of my experiences of setting up a web server under Linux. I will start with where/how to obtain Apache, then move on to installation, configuration, and finally how to get things running. This article is written from the point of view of my system, which is a Red Hat 4.0 system with v2.0.25 of the kernel. However, a "generic" installation or a similar setup should apply as well.

Where To Get Apache

The obvious place to get the latest version of Apache is off of the Apache web site: http://www.apache.org. The source distribution file is apache_1.1.1.tar.gz while the Linux ELF binaries is apache_1.1-linux-ELF.tar.gz. Grab what you find is necessary...

If you are running Red Hat Linux 4.0 like I am, during the installation process you are allowed to select whether or not you want to install a web server. If you do, Red Hat 4.0 includes the latest Apache and installs everything automatically with a default configuration. This default configuration even RUNS correctly without any modifications! However, even in this case, please read my notes and preferences regarding installation in the next section.

Typically, unless you need to add special modules or features, the binary distribution or the default Red Hat installation should be fine. However, let's say you wanted to run Apache as a proxy server. In this case, you would need the source so you can compile the proxy module as part of the binary.

(Note: I have heard rumors that the binary included with Red Hat 4.0 has some bugs. I have yet to encounter any myself, so take that rumor with a big grain of salt.)


I'm not going to cover compiling Apache since it's actually a fairly painless process and pretty well documented. Given that, let's move on to actual installation...

Personally, I like to group all the web server files together in a centralized location. If you are installing this manually, then this is something you can do from the outset, and I highly suggest doing this since it will reduce administration headaches.

If you had Apache installed automatically as part of the Red Hat installation procedure, then things will NOT be centralized! In fact, I thought the file placement scheme was one of the most confusing I've ever encountered. Here's what the Red Hat installation does:

web server binaries /usr/sbin/httpd
config files /etc/httpd/conf/*
log files /etc/httpd/logs/*
web server root
(contains cgi, icons/images, and html files)

I found this to be really disorganized, so I ended up putting mostly everything under one directory (I left the binaries in /usr/sbin):

    mkdir /httpd
    mv /etc/httpd/conf /etc/httpd/logs /home/httpd/* /httpd
    rmdir /home/httpd

You should end up with:


And then to preserve the original Redhat file locations:

    ln -s /httpd /home/httpd
    ln -s /httpd/conf /etc/httpd/conf
    ln -s /httpd/logs /etc/httpd/logs

Finally, I added this link since I felt that it made more sense:

    ln -s /httpd/logs /var/log/httpd

If you are installing and compiling Apache manually, you may want to have the original source files also located under /httpd (or whichever directory you have).


Apache has three main configuration files: access.conf, httpd.conf, and srm.conf. If you are running Red Hat 4.0, these files will already be set with the correct directory paths. If you centralized the locations of all these files, but made those symbolic links as I mentioned above, things will still be fine since the symbolic links preserves where Red Hat installed everything.

If you are doing a "generic" installation or have some other setup, then you will need to do the following:

In access.conf, change/update these directory entries:

    <Directory /httpd/html>
    <Directory /httpd/cgi-bin>

In httpd.conf:

    ServerRoot /httpd

In srm.conf:

    DocumentRoot /httpd/html
    Alias /icons/ /httpd/icons/
    ScriptAlias /cgi-bin/ /httpd/cgi-bin/

Essentially, these are the necessary directives in the config files that need to be updated with the new "centralized" organization.

For further configuration options, I will have to give the standard statement, "Please refer to the docs." :)

Starting/Running the Web Server

To make a long story short, you simply to need to execute the binary "httpd". Typically, this is done when the system starts up, in one of the rc files.

In Red Hat 4.0, it has more of a System V'ish startup style. In /etc/rc.d/init.d resides httpd.init, which is the script used to start and stop httpd. You can also execute this by hand if you find the need.

For other systems (or a manual install), I suggest starting httpd after most other services have started (i.e.: put it in rc.local). A simple line such as

    /usr/sbin/httpd &

will suffice.

Obviously, it must start after tcp/ip networking has been started. :)

What's Next

Needless to say, I didn't cover actual configuration options and how to manage your web server. The configuration options I leave to the Apache manual. Managing the web server itself depends on what kind of web site you want to run. My own system does not run a "real" web site; in other words, I don't advertise it for anything because it serves no real purpose other than for my own experimentation. However, you are more than welcome to take a look at it since it does have a bunch of Linux related links to it. The URL can be found at the end of this article.

Other than that, I would love to hear any comments and/or criticisms you may have about what I wrote. Originally, my plan was to write a monthly article about running/managing a web server under Linux. However, short of actually writing a manual on configuring Apache (which the Apache documentation is good enough as a reference), I don't know what else to write about since there may not be all that much to write about.

However, one idea for a monthly thing that might be good is to collect hints, tricks, and other useful information related to running a web server under Linux. Think of it more as a "2 cent tips for a linux web server." If anyone is interested in this, please drop me a note!

Copyright © 1996, Andy Kahn
Published in Issue 12 of the Linux Gazette