11.3 Running Apache

Installing and configuring the Apache web server is not difficult. Once your web server is up and running, other Internet users can view and download documents within the web-enabled directories on your Linux system. This section explains the installation and configuration of Apache, the most popular web server on the Internet.

11.3.1 Installing Apache

Use the Package Management Tool to install the Web Server package group, which contains the Apache web server. This package group contains over two dozen optional packages. Unless you specifically require the support they provide, you should deselect them before initiating the installation. However, you should not generally deselect the optional redhat-config-httpd package, which is helpful in configuring Apache.

When you install Apache, the procedure may fail owing to missing packages. It appears that Red Hat's developers erroneously specified some required packages in the Apache web server package group as optional. Select the following packages for installation and try again:

  • commons-logging

  • xerces-j

  • jakarta-regexp

  • bcel

  • redhat-java-rpm-scripts

  • xalan-j

11.3.2 Configuring Apache

Configuring a web server can be as easy or as difficult as you choose. Like other web servers, Apache provides seemingly countless options. As distributed with Red Hat Enterprise Linux and Fedora Core, Apache has a default configuration that generally requires only a little tweaking before use. Apache's configuration files reside in the directory /etc/httpd/conf. For historical reasons that no longer apply, Apache has three configuration files:

  • access.conf

  • httpd.conf

  • srm.conf

However, the only configuration file that's currently used is httpd.conf. The easiest way to perform a basic configuration of Apache is with the Apache Configuration Tool. To configure Apache, choose System Settings Server Settings HTTP from the main menu. The main configuration screen (Figure 11-10) appears.

Figure 11-10. The Apache Configuration Tool

The Apache Configuration Tool contains four tabs: Main, Virtual Hosts, Server, and Performance Tuning. The Main tab lets you specify the following:

Server Name

This is the hostname of your system. Often, this will be www.domain.com, where domain.com is the name of your domain.

Webmaster email address

Any messages concerning the web server will be sent to this address.

Available Addresses

This is the IP address (or addresses) on which the web server listens.

When offering a web server (or any other server) you should make sure that a DNS server is available to resolve your host's name to its IP address. If your host is reachable on a network but the domain administrator won't add your host's name to the DNS database, you can specify the web server's IP address as its server name. Users can then contact the web server using its IP address rather than its host name.

You should specify the Server Name and Webmaster email address. Unless your system has multiple network adapters or you want to run the web server on a nonstandard port (that is, a port other than 80), you don't need to modify the Available Addresses configuration item.

The Virtual Hosts tab, shown in Figure 11-11, lets you specify virtual hosts. Virtual hosting is a feature that lets you host multiple web sites with a single IP address. For example, both http://www.myfirstsite.com and http://www.myothersite.com could be hosted on the same system using a single IP address. Virtual hosting is not compatible with HTTP 1.0 browsers. However, only a small minority of web users currently use HTTP 1.0 browsers, which are quite out of date.

Figure 11-11. The Virtual Hosts tab

The Server tab (Figure 11-12) lets you specify the location of important files and directories and the user account and group used by Apache. You generally should not alter these configuration items.

Figure 11-12. The Server tab

The Performance Tuning tab (Figure 11-13) provides access to configuration items that let you optimize Apache's performance. Unless your web server will see very heavy service, you should reduce the maximum number of connections. A value of 15 is more than appropriate for a personal web server.

Figure 11-13. The Performance Tuning tab

If you're interested in exploring the many other configuration options provided by Apache, see the Apache documentation, available at http://httpd.apache.org/docs-2.0.

11.3.3 Starting and Stopping Apache

Once you've configured your web server, you can start, stop, and restart it by using the Service Configuration Tool. You can also associate the httpd service with one or more runlevels, so that it starts automatically when your system boots. You can use Mozilla to test your web server by pointing Mozilla to the URL http://localhost/.

If you're using Red Hat Enterprise Linux, you should see a screen that resembles Figure 11-14. If you're using Fedora Core, you should see a similar page with a different title and color scheme.

Figure 11-14. The Apache start page as viewed with Mozilla

Once you can access your web server locally, try accessing it from a remote computer. This should be as simple as forming a URL that includes the fully qualified hostname or IP address of your system (that is, the host and domain names), for example, http://mysystem.mydomain. However, bear in mind that you can reference your system by hostname only if its IP address is known to the DNS server or contained in the client's /etc/hosts file.

If you change Apache's configuration, you must restart the server so that the server reads the revised configuration file. You can do so by using the Service Configuration Tool.

11.3.4 Creating Web Pages

You can create HTML pages in /var/www/html, owned by the root user account. These pages are accessible via the URL http://www.domain.com, where domain.com is the name of the host.

Alternatively, users can create a public_html subdirectory within their home directory, for example, /home/joepublic/public_html. There, they can publish files that are web-accessible. To access such files, use a special URL that consists of a tilde (~) followed by the name of the user account. For example, http:// www.domain.com/~joepublic refers to the user joepublic's web directory. However, support for user publishing of web pages is not enabled by default. To enable it, edit the file /etc/httpd/conf/httpd.conf, changing the line:

UserDir disable


UserDir enable all

Any configuration changes made manually are overridden when you launch the HTTP configuration tool. Therefore, you must remake them each time you run the tool.

Then, restart the httpd service. If you want to permit only specified users to publish web pages, replace the keyword all with a list of usernames, separating each from the next with one or more spaces:

UserDir enable billmccarty andyoram

You must also change the permissions of files and directories you want to be accessible via the Web. For the user joepublic's web pages to be web-accessible, the apache user account or group must have execute access to the directories /home, /home/joepublic, and /home/joepublic/public_html. Moreover, if automatic directory indexes are desired, the apache user account or group must have read access to the /home/joepublic/public_html directory. The files themselves must be readable by the apache user.

The rule of thumb is to give the /home/joepublic directory permissions 711 and the /home and /home/joepublic/public_html directory permissions 755. Within /home/joepublic/public_html, directories should have permissions 755 and files should have permissions 644. However, your particular needs may dictate that other permissions should be used.

If you have trouble accessing web pages on your server, check Apache's log files, which you can view via the System Logs Tool. The log files may provide valuable clues to help you understand what's going wrong.