Installing Apache Server

Download:

Download httpd-2.0.xx.tar.gz (xx is version number), the Apache2 tarball from Apache.org. You may also choose version 1.3.xx.

Preparation:

The following steps will help you install Apache2 server in /usr/local/apache2. It is assumed that tarball is in /home/user and you know how to get there. All instructions except unpack are issued from the untar directory of /home/user/httpd-2.0.xx


Unpack:

tar zxvf may also be used.
# tar zxf httpd-2.0.xx.tar.gz

Change to Apache2 source directory:

# cd httpd-2.0.xx

Configure:

Note: The back slash tells Linux console to expect another line.
If there is no error, proceed.
# ./configure --prefix=/usr/local/apache2 \
--enable-mods-shared=most

Install:

If there is no error, proceed.
# make

# make install

Preparing Apache2 for PHP:

vi is a Unix editor.
# vi /usr/local/apache2/conf/httpd.conf

Find DirectoryIndex line and add index.php to it, like
DirectoryIndex index.html index.html.var index.php

Find AddType section (if you can't find it, go to the end of the file), add:
AddType application/x-httpd-php .php

Create Apache daemon:

# cp /usr/local/apache2/bin/apachectl /etc/init.d/httpd

Create run level 3 and 5 links:

Apache2 server will automatically start with the next reboot.
# ln -s /etc/init.d/httpd /etc/rc3.d/S85httpd
# ln -s /etc/init.d/httpd /etc/rc3.d/K85httpd
# ln -s /etc/init.d/httpd /etc/rc5.d/S85httpd
# ln -s /etc/init.d/httpd /etc/rc5.d/K85httpd

Starting Apache2 server:

# /usr/local/apache2/bin/apachectl start

Testing:

apache-testpage: The Apache test page
Point your browser to http://localhost and you will see the Apache test page.


If you use Webmin

You might want to check and change file paths in Webmin.





Q&A

How do I get rid of that using localhost as our domain message?

Server name has not been configured. You can edit httpd.conf and change ServerName localhost to ServerName myhost.mydomain.tld.

I don't have a TLD, what admin email should I use?

Any valid email address will do. All webmasters are expected to comply to this requirement. If you do not include an admin email address, the TLD owner gets the blame and might decide to boot you.

What is a webmaster?

A webmaster is usually but not always the owner of a web site.

How do I host downloads?

With the exception of index page, as defined in DirectoryIndex of httpd.conf, all files in a web directory can be downloaded. When a packet arrives at port 80, Apache serves the index page and blocks view and access to other files. Of course, Apache also blocks access in other ways. A common practice is to put all downloads into a directory, for example pub, and set a link to it on the index page. An example can be found in Hosting Downloads on phpBB. Be warned, HTTP downloads are anonymous and you can not effectively control multi-threaded downloaders on a standard installation.

Why can't I write to the web directory as a user?

It is not a good idea to allow user write permission to web directory. The default web directory is owned by [user] apache while the sample web, ROCP, is owned by root.

Who is the Apache user?

Apache usually run as system user nobody or apache in the group of the same name. If you do not want to use root, you should chown the web directory to Apache group and add a user a member of that group.

Can I host a site within my home?

There are two ways to do that. One is to symlink from webroot to the site directory in your home. This method might expose your home if Apache is not sufficienty secured. The other method is to use Apache mod_userdir which will let every home user host his/her site without access to webroot. Once installed, create a directory called public_html and put a file called index.html (almost a must) in it. This site is accessible at http://myhost.mydomain.tld/~user where user is the name of the home user. (Caution: Do not host a root userdir site!)