Home arrow Apache arrow Page 12 - Getting Started with Apache
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

Once the server is running and you have dealt with any error messages, the next step is to test it. The most obvious way to test a Web server is with a Web browser, but you can also test from the command line.

Before trying to test the server, create a short but valid home page, so Apache has something to send. You can use the page Apache installs by default or put together your own, for example:

<html>
<head>
<title>Welcome to Alpha Complex</title>
</head>
<body>
The Computer is Your Friend
</body>
</html>

This is a somewhat minimal HTML document, but itís good enough for testing purposes. Put this in a file called index.htm or index.html and place it in the directory specified as the document root in Apacheís configuration.

NOTE If no document root has been specified, Apache looks for a directory called htdocs under the server root. If neither the server root nor the document root is defined, the default home page would be /usr/local/apache/htdocs/index.html .

Testing with a Browser

The simplest and most obvious approach is to start a Web browser and point it at the server using the serverís configured root domain name if it has one, or localhost, which should work on any Unix system. Alternatively, the configured IP address of the server should also work:

Domain name : http://www.alpha-complex.com/
IP Address : 192.168.1.1
Local Host : http://localhost/
Local Host IP : 127.0.0.1

Apache needs to know what domain or domains itís to handle, but itís not responsible for managing them, only responding to them. In version 1.3, Apache listens to all valid IP addresses for the host itís running on by default, so an attempt to contact any valid network name or IP address for the host with a browser should cause Apache to respond. Apache 2 requires that you specify at least one Listen directive; it determines whether Apache will receive the connection request.

If youíre setting up Apache to use a particular domain name but donít yet have a proper IP address for it, you can associate www.alpha-complex.com in this example with the loopback IP address 127.0.0.1 as a temporary stand-in, which will allow the domain name to work without a real network interface in place.

NOTE For more information on domain names and IP, see the introductory section about TCP/IP networking in Chapter 1 and the Listen directive.

Testing from the Command Line or a Terminal Program

Itís also possible to test the server either directly from the command line or by using a basic terminal program. This can be especially handy when checking the values of response headers that are otherwise hard to see. On Unix systems, the telnet command can be used to make a network connection to the server. On other operating systems, a telnet utility is usually available, and syntax and location vary from system to system. Most browsers support a telnet mode.

To contact the server with telnet, type the following under both Windows and Unix:

telnet localhost 80

or in a browser, enter this URL:

telnet://localhost:80

If Apache is running and responding to connections, this should produce something similar to the following (some telnet commands are more verbose than others):

Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.

At this point, you may type in any valid HTTP protocol command, and if the server is working correctly, you can expect a response. For example, the following will return a short informational message about the server:

HEAD / HTTP/1.0

Because HTTP 1.0 and newer allows you to send additional information in the form of additional header lines, you need to press the Return key twice after this command to let the server know the whole request has been sent.

What does this mean? HEAD tells the server you just want header information. The / is the URL you want, which needs to be valid even if you donít actually want the page; / must be valid on any server, so itís safe to use here. HTTP/1.0 tells Apache youíre sending a version 1.0 HTTP command. Without the HEAD command, Apache will assume that youíre sending HTTP 0.9 commands because the HEAD command was introduced in HTTP 1.0. Youíll need to explicitly set the HTTP version, or Apache will return the following error:

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html>
<head>
<title>400 Bad Request</title>
</head>
<body>
<h1>Bad Request</h1>
Your browser sent a request that this server could not
understand.<p>client sent invalid HTTP/0.9 request:
head </p>
</body>
</html>

If the server is working correctly, HEAD / HTTP/1.0 should produce something like this, depending on the exact configuration:

HTTP/1.1 200 OK
Date: Mon, 28 Jul 2003 14:22:23 GMT
Server: Apache/2.0.46 (Unix) DAV/2
Connection: close
Content-Type: text/html; charset=ISO-8859-1

This tells you what version of HTTP Apache supports (1.1 for any version from 1.2 and newer), the time of the request, and the server type and version. In this case, Apache, of course, plus the operating system. Connection: close tells you that Apache

will close the connection after responding, and Content-Type tells you what kind of document you asked about. This particular home page is an HTML document. If the server responds to a HEAD command, itís time to try to retrieve the homepage of the Web site with this:

GET /

This will cause Apache to interpret the request as an HTTP version 0.9 command and should produce the homepage:

Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
GET /
HTTP/1.1 200 OK
Date: Mon, 28 Jul 2003 14:22:31 GMT
Server: Apache/2.0.46 (Unix) DAV/2
Connection: close
Content-Type: text/html

<html>
<head>
<title>Welcome to Alpha Complex</title>
</head>
<body>
The Computer is Your Friend
</body>
</html>

You could also use a protocol parameter to tell Apache you want to use HTTP version 1.0:

GET / HTTP/1.0

If you do this, you have to press Return twice to tell Apache you donít want to send any headers. If you were to specify HTTP/1.1, you would be obliged to send a hostname as a header. You could do this anyway with either 1.1 or 1.0, and if there are virtual hosts set up, you can test each one individually, for example:

GET / HTTP/1.1
Host: www.alpha-complex.com

and:

GET / HTTP/1.1
Host: www.alpha-prime.com

If Apache responds correctly to each GET request with the appropriate home page, you have a working server.

Unless it has been configured otherwise with the KeepAlive directive, Apache will keep a connection open after handling an HTTP/1.1 request. This allows you to type in another request immediately. With HTTP/1.0, the connection is dropped after the response is sent.  

This chapter is from Pro Apache by Peter Wainwright. (Apress, 2004, ISBN: 1590593006). Check it out at your favorite bookstore today. Buy this book now.



 
 
>>> More Apache Articles          >>> More By Apress Publishing
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

APACHE ARTICLES

- Apache Unveils Cassandra 1.2
- Apache on ARM Chips? Dell and Calxeda Help M...
- The Down Side of Open Source Software
- VMware Unveils Serengeti for Apache Hadoop
- SAP Takes Steps to Improve Hadoop Integration
- Looking to Hone Apache Hadoop Skills?
- How to Install Joomla on WAMPP
- Working with XAMPP and Wordpress
- GUI Available for Apache Camel
- Reduce Server Load for Apache and PHP Websit...
- Creating a VAMP (Vista, Apache, MySQL, PHP) ...
- Putting Apache in Jail
- Containing Intrusions in Apache
- Server Limits for Apache Security
- Setting Permissions in Apache

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: