home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  

Practical mod_perlPractical mod_perlSearch this book

3.10. How Can I Tell if mod_perl Is Running?

There are several ways to find out if mod_perl is enabled in your version of Apache. In older versions of Apache (versions earlier than 1.3.6), you could check by running httpd -v, but that no longer works. Now you should use httpd -l.

It is not enough to know that mod_perl is installed—the server needs to be configured for mod_perl as well. Refer to Chapter 4 to learn about mod_perl configuration.

3.10.2. Testing by Viewing /perl-status

Assuming that you have configured the <Location /perl-status>section in the server configuration file as explained in Chapter 9, fetch http://www.example.com/perl-status/ using your favorite browser.

You should see something like this:

Embedded Perl version 5.6.1 for Apache/1.3.24 (Unix)
mod_perl/1.26 process 50880,
running since Sat May 18 18:08:01 2002

3.10.4. Testing via a CGI Script

Another method to test for mod_perl is to invoke a CGI script that dumps the server's environment.

We assume that you have configured the server so that scripts running under the location /perl/ are handled by the Apache::Registry handler and that you have the PerlSendHeader directive set to On.

Copy and paste the script below. Let's say you name it test.pl and save it at the root of the CGI scripts, which is mapped directly to the /perl location of your server.

print "Content-type: text/plain\n\n";
print "Server's environment\n";
foreach ( keys %ENV ) {
    print "$_\t$ENV{$_}\n";

Make it readable and executable by the server (you may need to tune these permissions on a public host):

panic% chmod a+rx test.pl

Now fetch the URL http://www.example.com:8080/perl/test.pl (replacing 8080 with the port your mod_perl-enabled server is listening to). You should see something like this (the output has been edited):

SERVER_SOFTWARE Apache/1.3.24 (Unix) mod_perl/1.26
DOCUMENT_ROOT   /home/httpd/docs
[more environment variables snipped]
MOD_PERL        mod_perl/1.21_01-dev
[more environment variables snipped]

If you see the that the value of GATEWAY_INTERFACE is CGI-Perl/1.1, everything is OK.

If there is an error, you might have to add a shebang line (#!/usr/bin/perl) as the first line of the CGI script and then try it again. If you see:


it means you have configured this location to run under mod_cgi and not mod_perl.

Also note that there is a $ENV{MOD_PERL} environment variable if you run under a mod_perl handler. This variable is set to the mod_perl/1.xxstring, where 1.xx is the version number of mod_perl.

Based on this difference, you can write code like this:

    # perl5.004 or better is a must under mod_perl
    require 5.004 if $ENV{MOD_PERL};

If you develop a generic Perl module aimed at mod_perl, mod_cgi, and other runtime environments, this information comes in handy, because it allows you to do mod_perl-specific things when running under mod_perl. For example, CGI.pm is mod_perl-aware: when CGI.pm knows that it is running under mod_perl, it registers a cleanup handler for its global $Q object, retrieves the query string via Apache->request->args, and does a few other things differently than when it runs under mod_cgi.

Library Navigation Links

Copyright © 2003 O'Reilly & Associates. All rights reserved.