11.4 Running CGI Scripts with mod_perl
What most people want to do with
mod_perl
is improve
CGI performance.
The
mod_perl
installation assumes this request by enabling the With Apache::Registry, each individual CGI program is compiled and cached the first time it is called (or whenever it is changed), and then remains available for all subsequent instances of that CGI script. This process avoids the costs of startup time. Whereas most CGI scripts are kept in /cgi-bin/ , scripts that use Apache::Registry are placed in a separate directory, e.g., /perl-bin/ . The access.conf Apache configuration file needs to point to this directory by setting an alias and defining a handler for this new location. Instead of using theAlias /perl-bin/ /usr/local/apache/perl-bin/ <Location /perl-bin> SetHandler perl-script PerlHandler Apache::Registry PerlSendHeader On Options ExecCGI </Location>
cgi-script
handler, we use
the
perl-script
handler to give control to
mod_perl
.
Next, the
PerlHandler
directive tells
mod_perl
that the Apache::Registry module should
be used for serving all files in that directory.
PerlSendHeader
is another
mod_perl
-specific
directive; in this case, it tells
mod_perl
to send response
lines and common headers - by default, none are sent. (For NPH scripts,
you'll want to turn this feature off again.)
Options ExecCGI
is a standard Apache header
needed to tell Apache to treat the script as a CGI script.
If you want to load Perl modules in addition to Apache::Registry, you can use the PerlModule directive: If you include this line, you shouldn't need to explicitlyPerlModule CGI
use CGI
in each Perl CGI script anymore, as CGI.pm
will be loaded directly from the Apache server. Up to ten
modules can be listed with the
PerlModule
directive.
CGI scripts in the new directory should work now. However, if you have problems, the mod_perl manpage offers some words of wisdom:
In addition, it is recommended that you should use a recent version of Perl and of CGI.pm. You should scan the mod_perl documentation for the very latest compatibility news. Copyright © 2001 O'Reilly & Associates. All rights reserved. |
|