O'Reilly logo

Apache Cookbook by Rich Bowen, Ken Coar

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

8.5. Testing That CGI Is Set Up Correctly

Problem

You want to test that you have CGI enabled correctly. Alternatively, you are receiving an error message when you try to run your CGI script and you want to ensure the problem doesn't lie in the web server before you try to find a problem in the script.

Solution

#! /usr/bin/perl
print "Content-type: text/plain\r\n\r\n";
print "It's working.\n";

And then, if things are still not working, look in the error log.

Discussion

Because Perl is likely to be installed on any Unixish system, this CGI program should be a pretty safe way to test that CGI is configured correctly. In the event that you do not have Perl installed, an equivalent shell program may be substituted:

#! /bin/sh
echo Content-type: text/plain
echo
echo It\'s working.

And, if you are running Apache on Windows, so that neither of the above options works for you, you could also try this with a batch file:

echo off
echo Content-type: text/plain
echo.
echo It's working.

Make sure that you copy the program code exactly, with all the right punctuation, slashes, etc., so that you don't introduce additional complexity by having to troubleshoot the program itself.

In either case, once the program is working, you should see something like the following screen capture (see Figure 8-1).

Your CGI program worked

Figure 8-1. Your CGI program worked

The idea here is to start with the simplest possible CGI program to ensure that ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required