Personal Apache Web Server Guide Henry H. This guide will instruct users on howto deploy an Apache web server from home for various uses. 1.0 2005-05-17 Introduction
A brief Introduction to Apache

Apache is by far the most popular web server on the Internet. As of February 2005 Netcraft has reported more than 68% of sites surveyed use Apache. Due to it's open source nature and wide popularity it stands to reason why shouldn't a guide for apache installation should be made.

This guide is ultimately aimed at the home user who wants to put up a personal webpage from home. With the widespread increase of broadband and Linux, more and more people can start putting up personal webpages for blogging, home-made picture albums, hobby sites, etc.

Average users may think operating your own HTTP server is a lot more difficult and time consuming than it really is but the truth is if you just want to host pictures of the family then it really is not difficult.

Users should consider this guide a general, quick and easy way to get started with Apache. Full-blown websites involve a lot of work in configuring and securing but this guide will make it easy for users to get started with the basics.

Installing Apache
Getting Started

Fortunately, Apache is available in portage and users are urged to get the latest version available in portage so that the latest stable bug fixes and security patches are installed.

# emerge sync
USE Flags

Generally, there are going to be a couple USE flags the user should be aware of before emerging Apache. Please enable the following flags that apply.

ipv6Enable IPv6 support for IP addressessslEnable SSL support for webpagesberkdbEnable Berkeley Database supportldapEnable LDAP (Lightweight Directory Access Protocol) Support
USE Flag Description
If you do not know what any of the above flag descriptions are referring to then it is ok to ignore them. If at a later time the need arises for any of the above flags you can always enable the flag and re-emerge Apache.

Please add the appropiate USE flags to your /etc/make.conf file under the USE category.

Emerging Apache

Compile time will vary from system to system but if you need a general estimate on compile time, an AMD 1.33Ghz Thunderbird with 512mb of RAM takes about 10 min.

# emerge apache
Configuration
Basic Config

After Apache has been emerged the user should be made aware of how to configure the Apache server. In this Chapter basic configuration options will be given. The main configuration file is located at /etc/apache2/conf/apache2.conf.

The first thing users will want to do is to select an IP address and Port for the Apache server to listen in on.

Selecting an IP and Port for Apache to listen on is called Binding.
# The listen directive is what is used to choose IP/Port.
# Most users only have 1 IP address on their computer so the only
# thing that needs to be set is the Port. The following will set
# Apache to listen in on Port 80. There is no need to specify
# an IP address since there is only 1 available on the computer.
Listen 80

# If the user would like Apache to listen on another port in addition
# to port 80 then add another Listen line. Apache now listens on
# Port 8000 and Port 80 if the user kept both lines in the config.
Listen 8000

# If users have multiple IPs then the following syntax can be used.
Listen 192.168.0.20:80
Listen 192.168.0.150:8000
Setting the location of the HTML and related files

The DocumentRoot directive determines where the HTTP related files will go on the system. Users can change the location of files to whatever they feel.

# This is the default location in the config file
DocumentRoot /var/www/localhost/htdocs

# The location could be changed to a directory located in a user's
# home directory as follows.
DocumentRoot /home/user/www
Setting Apache to run on startup

If the user would like Apache to startup each time the Linux system is brought up then adding Apache to the runlevel is needed.

# rc-update add apache2 default
Where to insert HTML files

By now the user has the very basics setup for Apache and now all that is needed is for the user to add whatever files he or she chooses. The document root for all Apache files is located at /var/www/localhost/htdocs if the user kept the default path location mentioned in this guide.

For now the user does not have to place anything in the DocumentRoot location. HTTP related files can be inserted whenever but for now the default files at /var/www/localhost/htdocs are more than enough to get an idea of how to start.

Starting up Apache

It is now time for the user to start up the Apache server.

# /etc/init.d/apache2 start

Apache can just as easily be brought down with the following command.

# /etc/init.d/apache2 stop
Browsing to a fresh new page

If the user kept the configuration file to default so that Apache listens to port 80 and the DocumentRoot is left untouched then the user can immediately begin to test the newly started server.

Users should open up their favorite browser and enter in 127.0.0.1 into the browser address. The browser should immediately load a default page stating in the first sentence that the installation of the Apache web server is a success.

The user can also enter in their IP as listed in ifconfig usually on eth0.
Restricting Apache to localhost

If the user would like to setup an Apache server for testing and would like to restrict access to just the local computer it can easily be done by using the Listen directive in the apache2.conf.

# 127.0.0.1 is the local loopback address to your computer
Listen 127.0.0.1:80
Keeping track of your Apache

It can be helpful to monitor your apache server for security or debugging web applications through the error log. By default, the error log is located in /var/log/apache2/error_log. There are also varying levels of log detail which are available.

# Default warning level is "warn"
LogLevel warn

# Highest warning level is "emerg"
LogLevel emerg
emergalertcriterrorwarnnoticeinfodebug
Warning Levels from highest to lowest

To actively monitor the Apache log file on say a desktop, users can use a xterm and execute the following command.

# tail -f /var/log/apache2/error_log
Summary

Congratulations to the user for a painless quick start on Apache.

Users are encouraged to check back on this guide for more updates concerning Apache user and configuration. Possible future content include a FAQ.

Please direct all bug reports to Gentoo's Bugzilla.