< Day Day Up > |
11.3 Running ApacheInstalling 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 ApacheUse 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.
11.3.2 Configuring ApacheConfiguring 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:
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 ToolThe Apache Configuration Tool contains four tabs: Main, Virtual Hosts, Server, and Performance Tuning. The Main tab lets you specify the following:
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 tabThe 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 tabThe 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 tabIf 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 ApacheOnce 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 MozillaOnce 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 PagesYou 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 to: 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 /home/joepublic/public_html directory. The files themselves must be readable by the apache user.
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. |
< Day Day Up > |