The Required "Hello, World" Script

Following in the great tradition of computer science, here's a quick script you can use to test your mod_perl installation that spits back a webpage with the message "Hello, world".

To create this script, change directories to the perl subdirectory of the main Apache directory and create a file named hello.pl using your text editor of choice.
 

 
lamonml@hespera> cd /usr/local/apache/perl
lamonml@hespera> sudo vi hello.pl

Insert the following Perl code into the file:
 

 
#!/usr/bin/perl

print "Content-type: text/html\n\n";

print <<END;
<HTML>
<HEAD>
<TITLE>Hello There</TITLE>
</HEAD>
<BODY>
Hello, world!
</BODY>
</HTML>
END

Now open up a web browser, and take a peek at what the script does by going to the URL http://myhost.com/perl/hello.pl

The "Hello, World" message should appear in your browser window.  If you refresh the page a few times, you'll notice that it loads a little faster than your average CGI script.  (Granted, the speed difference isn't that noticeable with a script this small.)

The Apache printenv Script

If you want to try a script that's got a little more meat to it, and at the same time verify that your CGI environment is being replicated properly, you might want to try the printenv script that ships with Apache.  By default, this script is located in Apache's cgi-bin directory.  The below commands make a copy of the script in the perl subdirectory and enable it.
 

 
lamonml@hespera> cd /usr/local/apache/cgi-bin
lamonml@hespera> sudo cp printenv ../perl
lamonml@hespera> sudo chmod 755 ../perl/printenv

You can see what this script generates by looking at the URL http://myhost.com/perl/printenv

Once you're done playing with this script, you'll probably want to delete it from the perl subdirectory just to be secure (it gives out a little too much information about your system to be safe).

Now you're ready to go - move your old CGI scripts over the the Apache::Registry directory, update your hypertext links, and watch your dyanmic pages move faster.