This article describes how to install an apache web server on Arch 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.
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.
Run the following commands:
sudo pacman -S httpd
Adding iptables rules for apache (optional)
The default Arch images for Slicehost do not have iptables configured to restrict any ports, and the Slicehost articles on configuring Arch 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/apachectl start
Similarly, you can stop apache with:
sudo /usr/sbin/apachectl stop
To restart apache gracefully, so existing connections aren't broken but new ones will use any recent configuration changes, run:
sudo /usr/sbin/apachectl graceful
Executing apachectl by itself will show what options can be passed to the command.
Starting apache at boot time
Ensure apache will start when the slice reboots by editing:
At the end of the file is a "DAEMONS" value that lists the services that will be started at boot time. Add "httpd" to the end of that list. The DAEMONS entry would then look something like:
DAEMONS=(syslog-ng network netfs crond sshd httpd)
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 "www.example.com" 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 "www.example.com" gets you to the document root of "/srv/http", to view the file at "/srv/http/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).
Apache's log files are located in the directory:
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:
The log file that records page accesses to the default site is:
Apache's configuration files are located in:
The main configuration file for the web server is:
The main configuration file sets up the default web site that will be served by apache, as well as defining any modules that will be enabled. It's well-commented so it's worth skimming the file to see what directives are included. Some highlights are:
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 the one Listen directive configured, apache will listen to port 80 on all available IP addresses.
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).
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. A brief example of a full Directory block is the default "/" Directory entry, which is very restrictive:
<Directory /> Options FollowSymLinks AllowOverride None </Directory>
There are additional config files in the directory:
The files in this directory will be included in the apache configuration only if their corresponding "Include" line at the end of httpd.conf is uncommented. By default a few files are included in the apache config, including:
The configuration options in httpd-default.conf describe some options that have default values in apache's base config, like connection timeouts and KeepAlive options.
There are a number of Slicehost articles on apache, including tutorials and information on configuring virtual hosts and some mods.
- -- Jered