This article describes how to install an apache web server on Red Hat Enterprise Linux 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 yum install httpd
Adding iptables rules for apache
The Slicehost articles on configuring RHEL slices leave ports 80 and 443 open.
If you are using the RHEL default iptables rules or have modified the Slicehost default rules, you can add rules for apache with the following commands:
sudo /sbin/iptables -I INPUT -p tcp --dport 80 -m state --state NEW,ESTABLISHED -j ACCEPT sudo /sbin/iptables -I OUTPUT -p tcp --sport 80 -m state --state ESTABLISHED -j ACCEPT sudo /sbin/iptables -I INPUT -p tcp --dport 443 -m state --state NEW,ESTABLISHED -j ACCEPT sudo /sbin/iptables -I OUTPUT -p tcp --sport 443 -m state --state ESTABLISHED -j ACCEPT
To save those rules so they'll take effect next time the slice is rebooted, run:
sudo service iptables save
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 running:
sudo /sbin/chkconfig httpd on
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 "/var/www/html", to view the file at "/var/www/html/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 mods 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 a number of Slicehost articles on apache, including tutorials and information on configuring virtual hosts and some mods.
- -- Jered