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.1. Checking the error_log FileOne way to check for mod_perl is to check the error_log file for the following message at server startup: [Sat May 18 18:08:01 2002] [notice] Apache/1.3.24 (Unix) mod_perl/1.26 configured -- resuming normal operations 3.10.2. Testing by Viewing /perl-statusAssuming 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.3. Testing via TelnetKnowing the port you have configured Apache to listen on, you can use Telnet to talk directly to it. Assuming that your mod_perl-enabled server listens to port 8080,[22] telnet to your server at port 8080, type HEAD / HTTP/1.0, and then press the Enter key twice:
panic% telnet localhost 8080 HEAD / HTTP/1.0 You should see a response like this: HTTP/1.1 200 OK Date: Mon, 06 May 2002 09:49:41 GMT Server: Apache/1.3.24 (Unix) mod_perl/1.26 Connection: close Content-Type: text/html; charset=iso-8859-1 Connection closed. The line: Server: Apache/1.3.24 (Unix) mod_perl/1.26 confirms that you have mod_perl installed and that its version is 1.26. 3.10.4. Testing via a CGI ScriptAnother 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 GATEWAY_INTERFACE CGI-Perl/1.1 DOCUMENT_ROOT /home/httpd/docs REMOTE_ADDR 127.0.0.1 [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: GATEWAY_INTERFACE CGI/1.1 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: BEGIN { # 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. 3.10.5. Testing via lwp-requestAssuming you have the libwww-perl (LWP) package installed, you can run the following tests. (Most likely you do have it installed, since you need it to pass mod_perl's make test.) panic% lwp-request -e -d http://www.example.com This shows you just the headers; the -d option disables printing the response content. If you just want to see the server version, try: panic% lwp-request -e -d http://www.example.com | egrep '^Server:' Of course, you should use http://www.example.com:port_number if your server is listening to a port other than port 80. Copyright © 2003 O'Reilly & Associates. All rights reserved. |
|