Barebones apache install for Debian

This article describes how to install an apache web server on Debian 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 aptitude update

sudo aptitude install apache2

Adding iptables rules for apache (optional)

The default Debian images for Slicehost do not have iptables configured to restrict any ports, and the Slicehost articles on configuring Debian 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.

/usr/sbin/apache2ctl

Starting apache at boot time

Ensure apache will start when the slice reboots by running:

sudo /usr/sbin/update-rc.d apache2 defaults

Where to put documents

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

/var/www

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 "www.example.com" pointing to your slice you could see the default index file in the document root by going to this URL:

http://www.example.com

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 "www.example.com" gets you to the document root of "/var/www", to view the file at "/var/www/mysite/mypage.html" you would use the URL:

http://www.example.com/mysite/mypage.html

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 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:

/var/log/apache2

By default only the root user has access to that directory, so you will need to use sudo to get a directory listing or view files.

The log file that records errors is:

/var/log/apache2/error.log

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

/var/log/apache2/access.log

Configuration files

Apache's configuration files are located in:

/etc/apache2

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

/etc/apache2/apache2.conf

The configuration for the default site is located in the file:

/etc/apache2/sites-available/default

It is good practice to create any other virtual hosts in the same directory, possibly using the default config file as a reference. Once a site is configured it can be enabled or disabled with the commands "a2ensite" and "a2dissite". For example, to enable the default site, enter the command:

sudo /usr/sbin/a2ensite default

And the default site can be disabled with the command:

sudo /usr/sbin/a2dissite default

Similarly, modules can be enabled and disabled with "a2enmod" and "a2dismod".

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)

(optional)

(use plain text or Markdown syntax)