Barebones apache install for Gentoo

This article describes how to install an apache web server on Gentoo with no extras. It's intended only for users who are experienced administrators or who just want a basic web server install with no details on including modules like PHP or customizing apache for their site.

Why "barebones"?

A barebones article is intended for users who just want to get a software package up and running with the default options and no frills. It's best used by either experienced Linux administrators or users needing to get a package installed to satisfy a prerequisite without going through extensive customization. Most users are advised to use the more in-depth tutorials found elsewhere in the Slicehost articles repository so they can better learn the software they are implementing.

For a more comprehensive survey of this topic, check the links in the "Further reading" section at the end of the article.

Installing apache

Run the following commands:

sudo emerge --sync
sudo emerge apache

You might optionally add the USE flag "apache2" to your /etc/make.conf file, then rebuild any already-installed software for which you want to enable apache support.

Adding iptables rules for apache (optional)

The default Gentoo images for Slicehost do not have iptables configured to restrict any ports, and the Slicehost articles on configuring Gentoo slices leave ports 80 and 443 open.

If you have added iptables restrictions yourself or have removed the Slicehost default rules for web servers, the iptables rules to add can look like this:

-I INPUT -p tcp --dport 80 -m state --state NEW,ESTABLISHED -j ACCEPT
-I OUTPUT -p tcp --sport 80 -m state --state ESTABLISHED -j ACCEPT
-I INPUT -p tcp --dport 443 -m state --state NEW,ESTABLISHED -j ACCEPT
-I OUTPUT -p tcp --sport 443 -m state --state ESTABLISHED -j ACCEPT

Starting and stopping apache

You can start apache with:

sudo /usr/sbin/apache2ctl start

Similarly, you can stop apache with:

sudo /usr/sbin/apache2ctl stop

To restart apache run:

sudo /usr/sbin/apache2ctl restart

Executing apache2ctl by itself will show what other options can be passed to the command.


Starting apache at boot time

Ensure apache will start when the slice reboots by running:

sudo /sbin/rc-update add apache2 default

Where to put documents

Apache will serve documents for the default site from the directory:


This directory is called apache's "document root". You can make documents available via the web by putting them in that directory or in a subdirectory. If you were to have "" pointing to your slice you could see the default index file in the document root by going to this URL:

To access files or subdirectories in the document root, think of the base URL for your web server as an alias for the document root, then add a path to the URL telling the web server to look deeper. For example, if "" gets you to the document root of "/var/www/localhost/htdocs", to view the file at "/var/www/localhost/htdocs/mysite/mypage.html" you would use the URL:

When no filename is specified in the URL apache will look for a default page like "index.html" or "index.htm" in the target directory before returning the default welcome page, an error, or a listing of files in the directory (depending on your configuration).

Log files

Apache's log files are located in the directory:


The log file that records errors is:


The log file that records page accesses to the default site is:


Configuration files

Apache's configuration files are located in:


The main configuration file, which cites other configuration files for more specific functions, is:


The configurations for the default sites are located in the directory:


Other config files containing either general configuration or module-specific configs are in the directory:


Many of the files in vhosts.d and modules.d have a line toward the beginning that looks like:

<IfDefine KEYWORD>

The "KEYWORD" is used to tell apache whether or not to include that file in its configuration.

The keywords are enabled in the file:


All keywords to be enabled are listed in the "APACHE2_OPTS" setting. The format for each keyword is:


Where the "-D" tells apache to define the keyword.


Some highlights from the virtual host files (and the default_vhost.include file, which is included in both default virtual hosts) are:

Listen 80

The "Listen" directive tells apache to listen to a port, an IP address, or a combination of the two. You can include more than one Listen directive. By default, with just one Listen directive configured, apache will listen to port 80 on all available IP addresses.

DocumentRoot "/var/www/localhost/htdocs"

The DocumentRoot directive, as it happens, tells apache where the document root is located. The document root is where apache will look first for files to serve (see the earlier section, "Where to put documents", for more on the document root).

<Directory "/var/www/localhost/htdocs">

The Directory directive starts a configuration block that applies the options it contains only to the defined directory and its subdirectories. There can be more than one Directory block in the httpd.conf file or the files it includes. A brief example of a full Directory block is the default "/" Directory entry in "/etc/apache2/modules.d/00defaultsettings.conf ", which is very restrictive:

<Directory />
    Options FollowSymLinks
    AllowOverride None

Further reading

There are a number of Slicehost articles on apache, including tutorials and information on configuring virtual hosts and some mods.

You can find a lot of useful information on using apache at the apache web server homepage as well as the apache web server documentation site.

  • -- Jered
Want to comment?

(not made public)


(use plain text or Markdown syntax)