How to Set Up Apache

 < Day Day Up > 



If you have Red Hat Linux, then Apache comes with it. And if you followed the instructions in Chapter 2, then it is already installed on your system. However, in case you are not sure, remember that you can go to the Start menu, select System Tools, and choose Packages to see if it is installed. You can add it if it’s not already installed.

Now we are going to need to modify a few files. To find them it would be best to use the File Manager, so your next step is to launch that application. If you will recall, when we first discussed File Manager, you where admonished to spend some time getting comfortable with it, as it would be used later in this book. If you still don’t feel comfortable with the File Manager, take the following steps slowly, consulting the images provided in this chapter to ensure that you are on the right track.

You will need to first find the /etc/httpd/conf directory. Use the File Manager to locate the etc directory, then open it. Within that directory you will find a subdirectory named httpd. Then you look under that directory for yet another subdirectory named conf. Browse through this until you find the httpd.conf file. When you find it, right-click on it and open it with Text Editor. This directory and file are shown in Figure 15.2.

click to expand
Figure 15.2: Finding the httpd.conf file.

Note 

Do not double-click on the file. If you do that, the document will be opened in a read-only mode, and you won’t be able to make any changes. Recall that many applications, including the File Manager, work like a Web browser. If you double-click on a file, it will open like a Web page, for viewing only.

You will see that this is a large text file with a lot of information in it. You may even feel a bit overwhelmed. There are dozens of settings available in this file. However, most of them are not required for basic Web server operation. These settings are important for advanced Web server operations that are beyond the scope of this book. Entire books have been written on Apache, and you would need to consult such a book to go deeper into Apache. There are only a few settings in this that you even care about. The most important is ServerName. Follow these steps and you can have your server running.

Note 

It will only be accessible from your machine. This is a test mode to see if the Apache server itself works properly. If all goes well, we will go back and change a few things to make it accessible from the entire Internet. Also note that the ServerName setting is sometimes commented out with a pound symbol in front of it. Delete the pound symbol.

  1. Set the ServerName = localhost. This is shown in Figure 15.3.

    click to expand
    Figure 15.3: The ServerName setting.

  2. Save the file.

  3. From a shell, type /etc/init.d/httpd start. The server should start and you get an OK message. This is shown in Figure 15.4.

    click to expand
    Figure 15.4: Starting the HTTPD service.

  4. Open your browser and go to http://localhost/. You should see the Apache default Web site. The screen you should see is depicted in Figure 15.5. If you do not see this screen, then one of the steps was executed in error; most likely your changing of the httpd.conf file. Common errors and their resolutions are discussed in just a few paragraphs.

    click to expand
    Figure 15.5: The default Web page.

If your test worked and you can see the basic Apache default page, it is time to make your server go live. To do this, there are just a few steps to follow.

  1. First stop the server. You do this by going to a shell and typing in /etc/init.d/httpd stop. This is shown in Figure 15.6.

    click to expand
    Figure 15.6: Stopping the HTTPD service.

  2. In the /etc/httpd/conf/httpd.conf file, change the following settings:

    1. Change servername to your registered URL or to your IP port such as 10.10.10.117:80. If you don’t remember your IP address, don’t worry. Just go to the shell and type in ifconfig. This will give you your IP address.

    2. Change listen to reflect the IP and port you want.

  3. Check the documentroot directory to make certain that is where you want your Web pages to be served from. The default is /var/www/html. Whatever directory you put as your documentroot is where Apache will look for Web pages.

4. From a shell, type /etc/init.d/httpd start.

You should now be running a Web server. Go to any other machine that is connected to the Internet and point the browser to http://yourserverurlorip. For example, you might point the browser to http://10.10.10.01 if that is the IP of your machine.

If you are running this from your home, then the chances are that you use an Internet service provider to get to your machine. For this to work all of the time, you will have to do two things:

  1. Leave your Internet connection running. If you are not connected to the Internet, no one can reach your Web server.

  2. Ask your ISP for a static IP address. Recall from our previous discussions of network configuration that this means you have the same IP address every time you log on. Without this, your IP may change, and then people trying to visit your Web site won’t find it.

    Note 

    Any time you change the configuration file, you must stop the Web server and restart it.

If you want to use a URL rather than an IP address, you will need to go through the appropriate company to register a domain name. For example, the author has his Web site registered as www.chuckeasttom.com. There are several companies that will perform this service for you for a small fee. A list of a few of the more widely known companies is provided here:

  • www.networksolutions.com

  • www.register.com/

  • www.cheap-domainregistration.com/

  • www.nic.us/

  • www.easyspace.com/

  • www.aitdomains.com/

You also can do a Web search using a search engine such as Yahoo! or Google to find other places to register your domain. This list is not an endorsement of any of these sites, it is only a starting point in case you don’t know where to go to register a domain name.

At this point your Apache Web server is almost ready to go. There is only one small hurdle to overcome. When you first installed Linux, you probably left the firewall settings at their default values. With many distributions, this blocks HTTP and FTP, and that will keep your Web server from being able to communicate. It is probably a good idea to go to your firewall settings (recall from earlier chapters that we explored where to find this) and make certain that HTTP and FTP packets are not being blocked.

In a perfect world, every reader would follow these steps and have his Web server up and running. However, we all know that we don’t live in a perfect world, and things do go wrong sometimes. It is possible that you typed in something incorrectly. It is also possible that something else went wrong. While there may be a seemingly endless number of possibilities, there are a few common problems and their resolution. For your convenience, they are listed in Table 15.2. Of course, the very first step in troubleshooting is to check the basics. The following are the four basic Apache troubleshooting steps. Check these before checking anything else:

  1. Is your Web server running?

  2. Is it connected to the Internet?

  3. Did you type in the address correctly without misspelling it?

4. Have you checked the error log for error messages?

If these steps don’t uncover your problem, then consider the options in Table 15.2.

Table 15.2: Common Problems

Problem

Resolution

When connecting to the IP address, the browser says Cannot Resolve IP Address, Already in Use.

If you have ServerName and Listen set to the same IP address, this error will occur. Either change Listen to another IP or comment it out altogether.

Apache fails to start

When you changed ServerName, you probably messed up the spelling, such as forgetting a space between ServerName and the name: ServerNameLocalHost instead of ServerName LocalHost, or ServerName=LocalHost instead of ServernameLocalHost.

Unknown errors

If you are having problems that you cannot otherwise diagnose, then you should check the error log. The default location for that is /usr/local/apache/logs/error_log. However, if you check the error setting in the httpd.conf file, you can find out exactly where your error log is. If none of that helps, try the online Apache Frequently Asked Questions at httpd.apache.org/docs/misc/FAQ.html. The four troubleshooting steps, the items in this table, or even the Apache documentation cannot solve every problem. However, the overwhelming majority of problems are configuration issues and can be solved by trying out these few steps.



 < Day Day Up > 



Moving From Windows to Linux
Moving From Windows To Linux (Charles River Media Networking/Security)
ISBN: 1584502800
EAN: 2147483647
Year: 2004
Pages: 247
Authors: Chuck Easttom

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net