12.2 Running Apache

Installing and configuring the Apache web server is not much more difficult than installing an FTP server. Moreover, web servers tend to be more secure than FTP servers, so a web server may be a better way for you to publish files. 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.

The Tux Web Server

Red Hat 8.0 ships with Tux, a web server developed by Red Hat. Tux may be the fastest web server available. The secret of Tux's speed is that it is integrated with the Linux kernel, so the overhead involved in serving a web page is minimal.

However, don't toss Apache overboard just yet. Tux can serve only static HTML pages. It can't be used with server-side includes, PHP, or other popular methods of serving web pages whose content is determined when they're served. When Tux is asked to serve a dynamic page, it can hand off the request to Apache, so Tux and Apache can work together to rapidly serve static web pages yet provide the full power and flexibility of Apache.

Unless you're planning to establish a high-traffic web site, you won't need to be concerned with Tux, which is somewhat complicated to configure. To learn more about Tux, which Red Hat calls Red Hat Content Accelerator, see http://www.redhat.com/docs/manuals/tux/TUX-2.2-Manual/.

12.2.1 Installing Apache

Use the Package Management Tool to install the Web Server package group, which contains the Apache web server.

12.2.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 Linux, 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 Server Settings HTTP Server from the GNOME or KDE menu. The main configuration screen, shown in Figure 12-1, appears.

Figure 12-1. The Apache Configuration Tool

The 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.

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 12-2, 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 www.myfirstsite.com and www.myothersite.com could be hosted on the same system using a single IP address. However, virtual hosting is not compatible with HTTP 1.0 browsers.

Figure 12-2. The Virtual Hosts tab

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

Figure 12-3. The Server tab

The Performance Tuning tab, shown in Figure 12-4, 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 12-4. The Performance Tuning tab

If you're interested in exploring the many other configuration options provided by Apache, see the Apache manual, which resides in /var/www/manual. You can view the file with Links or another HTML browser. Also, see the Apache web site (http://www.apache.org), which includes a tutorial on Apache configuration.

12.2.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/.

You should see a screen that resembles Figure 12-5.

Figure 12-5. 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.

12.2.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

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 directory /home/joepublic/public_html. 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.