Apache Webserver Setup Guide by Joey.
Created on November 29th, 1999.
Last updated on September 19th, 2003.

Apache, the most popular web server on the internet comes from the term "A PAtCHy server" since it was originally based off the NCSA httpd 1.3 code in early 1995. Apache can handle great server loads and run on sites that get over a million hits a day without any problems so as you see, it's stable, it's highly configurable and best of all, it's free.

The apache server comes in many different forms. There's RPM Packages, .deb Packages and of course, the source.

This installation guide will be based on version 1.3.x of the Apache Source for a few reasons. For one, I still haven't upgraded to Apache 2.x due to ongoing issues with PHP and other modules. 1.3.x is still widely used and still works like a charm. As well, I prefer using the source for the installation rather than binary packages (.rpm's, .deb's etc) so I can specify paths etc. It also gives you the ability to apply patches when needed and makes life easier if you have to recompile Apache to add support for PHP or mod_ssl etc.

The first thing you need to do is grab the Apache source from http://www.apache.org/dist/httpd/. At the time of updating this guide, the current version is 1.3.28. There are many files on their site but you only need the one called apache_1.3.28.tar.gz

Once you've download the file, move it to /usr/local/src (I like to keep all my untarr'ed sources in /usr/local/src) and untar it by running the following command:

tar -zxvf apache_1.3.28.tar.gz

That will create a directory called apache_1.3.28 in /usr/local/src. Enter into that directory and run the following commands:

./configure --prefix=/usr/local/apache
make
make install

This will install apache and all it's files into the /usr/local/apache directory. With the source installation there is only oneconfiguration file that needs to be edited, it is called httpd.conf and located in /usr/local/apache/conf. If you chose to install the DEB or RPM version, you will probably have to edit access.conf and srm.conf, so this guide will make no sense to you.

Go into your apache configuration file directory, /usr/local/apache/conf and open up the httpd.conf file with your favorite text editor (nano, pico, vi, joe, etc). The httpd.conf file is well documented but I'll include some of the important options you will want to change/configure.

One of the great features with Apache is the ability to create virtual hosts. This gives you the ability to host multiple web sites on the same server with only one instance of Apache running. Below is an example of a virtual host entry:


NameVirtualHost 216.187.106.215

<VirtualHost 216.187.106.215>
ServerName www.linuxhelp.ca
ServerAlias linuxhelp.ca www.linuxhelp.net linuxhelp.net
DocumentRoot /usr/local/apache/html/linuxhelp
ErrorDocument 404 /404.php
ErrorLog /usr/local/apache/logs/linuxhelp-error.log  
CustomLog /usr/local/apache/logs/access.log combined  
ScriptAlias /cgi-bin/ /usr/local/apache/html/linuxhelp/cgi-bin/
<Directory "/usr/local/apache/html/linuxhelp">
    Options FollowSymLinks Includes Indexes
    AllowOverride None
</Directory>
<Directory "/usr/local/apache/html/linuxhelp/cgi-bin">
    AllowOverride None
    Options ExecCGI
    Order allow,deny
    Allow from all
</Directory>
</VirtualHost>


<VirtualHost 216.187.106.215>
ServerName ldp.linuxhelp.ca
ServerAlias ldp.linuxhelp.net
DocumentRoot /usr/local/apache/html/ldp
ErrorLog /usr/local/apache/logs/ldp-error.log
CustomLog /usr/local/apache/logs/access.log combined
</VirtualHost>

This should be all the basics you need to get Apache up and running. Save and exit the httpd.conf (now is a good time to make a backup copy of it too) and then start up your Apache server by running the following as root:

/usr/local/apache/bin/httpd -f /usr/local/apache/conf/httpd.conf

After running the command you should be returned to the command prompt without any errors etc. If you want to make sure Apache is running you can type the following:

ps aux | grep httpd

And you should see a couple of lines that look something like this:
www-data 10128    0.0    0.5    2224 1108 ?   S    14:48   0:00   /usr/local/apache/bin/httpd

If you see something similar to the above then great, Apache is up and running on your machine. Now for the ultimate test, open up your favorite web browser and try to access your website by going to either http://www.example.com or http://yourhostmask.com http://yourIP or http://yourname.dynip.com. You will probably see the something like the page located here.

If for some reason apache failed to start up, it will probably tell you why. You should receive something like "something failed on line 204 of httpd.conf" etc. Simply open up the httpd.conf file again, go to that line and look for anything that doesn't seem right. You can also check your error.log file located at /usr/local/apache/logs/error.log to see if anything strange is going on. If you aren't sure what the error message means, try visiting http://www.google.com and searching for the error message. You'll be surprised at the results.

As I said in the beginning of this guide, Apache isn't really that hard to set up; their httpd.conf file is well commented and their documentation at http://httpd.apache.org/docs/

You might also want to visit our Guides Page and have a look at the various Guides that integrate other services (MySQL, PHP, .htaccess, Squid, SSL) with Apache.


Having trouble? Got questions? Require further assistance? If so please feel free to visit our Help Forums and ask the experts!