Quickstarting the Apache Web Server

If Apache wasn't installed during the Fedora installation, you can install it later from the DVD or CD that comes with this book. You will need the httpd package and optionally the httpd-manual package (named apache and apache-manual in earlier versions).

Here's a quick way to get your Apache Web server going. From here, you'll want to customize it to match your needs and your environment (as described in the section that follows).

1. Make sure that Apache is installed by typing the following from a Terminal window:

$ rpm -qa | grep httpd system-config-httpd-1.4.4-1.fc9

httpd-tools-2.2.8-3.i386

httpd-devel-2.2.8-3.i386

httpd-2.2.8-3.i386

httpd-manual-2.2.8-3.i386

The version number you see may be different. You need only the httpd package to get started. I recommend httpd-manual because it has excellent information on the whole Apache setup. The httpd-devel package includes the apxs tool for building and installing extension modules. The httpd-tools package includes tools for running benchmarks and managing passwords for Apache.

The system-config-httpd package contains a GUI-based Apache Configuration tool. Depending on the type of content you are serving, you might also add packages containing modules to run that code within the Apache server (such as mod_perl, mod_python, and mod_mono).

2. A valid host name is recommended if it is a public Apache server (for example, www.handsonhistory.com). If you don't have a real, fully qualified domain name, you can edit the /etc/httpd/conf/httpd.conf file and define the ServerName as your computer's IP address. Open the httpd.conf file (as the root user) in any text editor, search for the line containing ServerName www.example.com:80, and uncomment it. It should appear as follows:

ServerName www.example.com:80

To make the Web server available to your LAN, you can use your IP address instead of www.example.com (for example, ServerName 10.0.0.1). The :80 represents the port number (which is the default). For a public Web server, get a real DNS hostname. (Refer to Chapter 25 for information on DNS and making a server public.) No changes are required to this file to make Apache available on the local host.

3. Add an administrative e-mail address where someone can contact you in case an error is encountered with your server. In the /etc/httpd/conf/httpd.conf file, the default administrative address appears as follows:

ServerAdmin [email protected]

Change [email protected] to the e-mail address of your Apache administrator. 4. Start the httpd server. As root user, type the following:

# service httpd start

If all goes well, this message should appear: Starting httpd: [OK]. Now you're ready to go.

5. To have httpd start every time you boot your system, run the command as root user.

# chkconfig httpd on

6. To make sure that the Web server is working, open Firefox (or another Web browser) and type the following into the location box and press Enter:

7. You should see the Test Page for the Apache Web server, as shown in Figure 21-1. To access this page from another computer, you will need to enter your Apache server's host name or IP address.

Figure 21-1: Appearance of the Test Page indicates that the Apache installation succeeded.

TIP: It is not necessary to be connected to a network (or even to have a network connection) just to test the server or to view the files on your local Apache machine. Rather than specify the server's real name in the URL, just use "localhost" (that is, http://localhost/) from a browser on the same computer. In fact, it's best to fully test the configuration before making the server accessible on an unprotected network.

8. The Test Page is actually an error condition, indicating that you haven't added any content to your Web site yet. To get started, you can add an index.html file that contains your own home page content in the /var/www/html directory. Then you can continue to add your own content to that directory structure.

Now that your Web server is working (or at least, I hope it is), you should step through the next section. It helps you understand how to set up more complex Web server arrangements and protect your server from misuse. Stepping through that section will also help you troubleshoot your Web server, in case it isn't working.

TIP: If your Web server is accessible from your local host, but not available to others from your LAN or the Internet, you may need to change your firewall rules to allow greater access. Appendix B explains how to make your Web or other server accessible. In particular, you need to open tcp port 80 and possibly tcp port 443 (if you offer https content). Also, if SELinux is enabled, it may prevent access to your Web server that you might normally expect to work. To disable SELinux, type setenforce 0 as root. Or type man httpd_selinux to learn how to use SELinux with httpd.

Was this article helpful?

0 0

Post a comment