Setting Up a Webserver

Last updated: November 1, 1999
Development stage: Alpha

The World Wide Web is probably the primary reason of the Internet's explosive growth as a popular communications medium. So why not add to the wealth by running your own webserver? The most popular webserver by far is Apache, which already comes with many Linux distributions.

Chances are that you already have Apache installed, so you may skip the downloading process. Of course, downloading and compiling a new Apache gives you the advantage of knowing how to do it. The process is quite simple, even the configuration.

This document is in alpha status, so let me know if it works for you so I can update its status. That way I'll know if it works.

  1. Removing Old Apache
  2. Download
  3. Compile and Install
  4. Configuration
  5. Error Messages
  6. Creating Content
  7. Author's Notes

Removing Old Apache

Should you choose to remove any existing Apache, try typing rpm -e apache, if you're using Red Hat (or maybe another RPM-based distribution).

In Debian, use the apt-get remove apache command.

Let me know how to remove the default Apache package for other distributions so I may include them here. I don't want to look ignorant for a long time.


Apache is available all around the world in many FTP sites. There's a mirror list at the Apache website. As of now, Apache is at version 1.3.9, and at the rate it constantly develops, this document will probably fall behind when a new release comes out.

You can find a list of where you can download Apache at The filename for the file you're looking for goes something like "apache_1.3.9.tar.gz".

Compile and Install

You have downloaded Apache. If it's not already, put it in /usr/local/src/ and untar (tar -zxvf <apache_1.3.9.tar.gz>) it. It should extract to some directory called "apache-1.3.9" or similar, depending on what version number you've downloaded. Now move into the apache directory by typing cd apache-1.1.9 (or whatever version you've got).

Basically you can get Apache compiled by typing ./configure ; make in the Apache directory. make install will install it to /usr/local/apache by default. In /usr/local/apache/ there will be many subdirectories containing various files that you might want to tinker with.

At the least, you should make a symbolic link from /usr/sbin/httpd to /usr/local/apache/bin/httpd (assuming you installed Apache to the default location). Or, you can add /usr/local/apache/bin/ to root or user paths from ~root/.bashrc and /etc/profile, respectively.


Since you've now got Apache installed and ready to go, it's time to configure it. Move on down to /usr/local/etc/httpd/conf/ and copy all the "*.conf.default" files to their "*.conf" selves. That means you would copy httpd.conf.default to httpd.conf, srm.conf.default to srm.conf, and access.conf.default to access.conf. Those are all the files that you need to copy. Edit "httpd.conf" with your favorite text editor and uncomment the ServerName line. Put in your hostname or IP address in place of the fake one in the commented line, which probably changes each time you log on. For ServerAdmin, put in your e-mail address so that people visiting your webserver can e-mail you about any problems that arise. What you fill in is pretty straightforward.

Reading the comments and examples in the *.conf files for Apache will help you if you need to do any "advanced" tasks such as virtual domains or extra MIME types (if you don't know what these are, don't worry about them yet).

Location of Configuration Files on Distributions

If you're using Red Hat Linux, you should have the configuration files in /etc/httpd/conf/, if you had Apache installed already.

On SuSE 5.2, 5.3 and 6.0 the config files for Apache are located in /etc/httpd/. Thanks to Uwe Hermann ( for this information.

Thomas Smith writes, "On my Debian 2.1 system, the configuration files are in /etc/apache, and are httpd.conf, srm.conf, mime.types, and cron.conf. I would guess that not all of these are essential, but they are the default. The default directory for web pages is /var/www/."

For other distributions, I'm not sure. Please let me know if you can provide this information. You'll probably want to look in the /etc/ directory in the meantime.

Virtual Hosts

Many people need to run multiple web servers on one machine instead of one webserver per Linux machine. First you'll have to get a hostname assigned to the webserver, which can be a subdomain ( if you're on the domain) or a whole new domain registered through InterNIC (such as

Once you get past all the domain registration stuff and you've got many hostnames assigned to the same IP address, or if the machine is running under multiple IP addresses and multiple hostnames, you're ready to set up for virtual hosts.

Start out by editing /usr/local/apache/conf/httpd.conf. If you have Red Hat Linux with Apache installed already, the file is /etc/httpd/conf/httpd.conf. You'll see an example shown, looking like this:

# VirtualHost: Allows the daemon to respond to requests for more than one
# server address, if your server machine is configured to accept IP packets
# for multiple addresses. This can be accomplished with the ifconfig 
# alias flag, or through kernel patches like VIF.

# Any httpd.conf or srm.conf directive may go into a VirtualHost command.
# See alto the BindAddress entry.
#DocumentRoot /www/docs/
#ErrorLog logs/
#TransferLog logs/

That's commented out because your machine most probably does not own the hostname and therefore won't accept requests for it.

The basic way that this works is when someone requests a page on, say,, it won't go to, the original hostname of the machine. Although is an alias for, somebody asking for won't get the front page to because it's specified in httpd.conf to serve out /home/jgo/index.html when a request for is given through HTTP. When a request for is given, however, it won't serve out /home/jgo/index.html because only the requests for will give the web surfer /home/jgo/index.html. Some older browsers don't support virtual hosts, such as MS Internet Explorer 2.0, which came with early versions of Windows 95.

You can assign as many virtual hosts to your machine as you want, especially if the machine is a top-level domain such as That way you can assign the hostnames,,,,, and anything else you might be able to think of as a hostname. Just keep in mind that you should make sure the server can handle the load of all those domains.

To add subdomains, you need to have an understanding of BIND, the nameserver. Your domain must be registered with InterNIC, and the nameserver is in charge of getting subdomains set up. It sounds complicated, but it makes a whole lot more sense once you figure it out.

Setup of /etc/hosts

My observations about the setup of /etc/hosts is that each hostname has to be part of a higher-level domain; for example, if I wanted to name my machine neophobia, I'd either have to make the higher-level domain "localdomain" or "". Here's what each entry would look like:	localhost	localhost.localdomain

and:		neophobia

People with dynamic IP addresses (most dialup PPP users) can just use the IP address "" to represent their Internet IP. So, this is what my hosts file looks like:	localhost	localhost.localdomain		neophobia

After you're done with all that you wanted to do, try to start httpd by typing httpd as root. It is common and normal for you to have some errors, so feel free to e-mail me concerning any other errors that come up after you execute the httpd binary.

Error Messages

When you have httpd already running, the error message it gives will be bind: Address already in use, httpd: could not bind to port 80 or something similar. To fix this, do killall httpd and then httpd to restart it. Make sure you bind it to the correct hostname/IP address (read the paragraphs above).

Creating Content

By default you'll have to edit the HTML files in /usr/local/apache/htdocs/. The directory for CGI scripts is in /usr/local/apache/cgi-bin/.

On a default Red Hat installation you'll probably find what you need to edit in /home/httpd/html/, along with some directories. The CGI-bin will be in /home/httpd/cgi-bin/.

The htdocs-directory (DocumentRoot) is /usr/local/httpd/htdocs/ on SuSE 5.2, 5.3, and 6.0, according to Uwe Hermann (

Let me know of the filesystem layout for other distributions. I don't have immediate access to other distributions.

Author's Notes

There are more complex things you can do with Apache, and here I only cover the basics. There are special modules that come with Apache which I have little experience with, but I just want to let you know that they're available. Read the INSTALL file for instructions on this.

Questions, comments, and/or suggestions? You can e-mail me at joshuago at users dot sourceforge dot net.

Copyright © 1997-1999 Joshua Go (joshuago at users dot sourceforge dot net). All rights reserved. Permission to use, distribute, and copy this document is hereby granted. You may modify this document as long as credit to me is given.