Configuring mod_perl 2.0 for Win32
This document discusses how to configure mod_perl 2.0.
Add this line to C:/Apache2/conf/httpd.conf:
LoadModule perl_module modules/mod_perl.so
Be sure that the path to your Perl binary (eg, C:/Perl/bin) is in your PATH environment variable. You could also add the directive
PATH
LoadFile "/Path/to/your/Perl/bin/perl5x.dll"
to httpd.conf to load your Perl dll. You may also want to use a start-up script to load commonly used modules; this can be done with a directive as, eg,
PerlRequire "C:/Apache2/conf/extra.pl"
where a sample start-up script C:/Apache2/conf/extra.pl is
use Apache2 (); use ModPerl::Util (); use Apache::RequestRec (); use Apache::RequestIO (); use Apache::RequestUtil (); use Apache::Server (); use Apache::ServerUtil (); use Apache::Connection (); use Apache::Log (); use Apache::Const -compile => ':common'; use APR::Const -compile => ':common'; use APR::Table (); use Apache::compat (); use ModPerl::Registry (); use CGI (); 1;
The Apache2 module is used to add to @INC the relevant directories underneath, eg, /Perl/site/lib/Apache2/ used when building mod_perl 2.0 with an MP_INST_APACHE2=1 option to perl Makefile.PL (the PPM packages discussed above were built this way). Apache::compat is used to provide backwards compatibility with mod_perl 1.0. ModPerl::Registry, named so as not to conflict with Apache::Registry of mod_perl 1.0, is used for registry scripts.
Apache2
@INC
MP_INST_APACHE2=1
perl Makefile.PL
PPM
Apache::compat
ModPerl::Registry
Apache::Registry
Using ModPerl::Registry to speed up cgi scripts may be done as follows. Create a directory, for example, C:/Apache2/perl/, which will hold your scripts, such as
## printenv -- demo CGI program which just prints its environment ## use strict; print "Content-type: text/html\n\n"; print "<HTML><BODY><H3>Environment variables</H3><UL>"; foreach (sort keys %ENV) { my $val = $ENV{$_}; $val =~ s|\n|\\n|g; $val =~ s|"|\\"|g; print "<LI>$_ = \"${val}\"</LI>\n"; } #sleep(10); print "</UL></BODY></HTML>";
Note that Apache takes care of using the proper line endings when sending the Content-type header. Next, insert in C:/Apache2/conf/httpd.conf the following directives:
Alias /perl/ "/Apache2/perl/" <Location /perl> SetHandler perl-script PerlResponseHandler ModPerl::Registry Options +ExecCGI PerlOptions +ParseHeaders </Location>
whereby the script would be called as
http://localhost/perl/name_of_script
The PerlOptions +ParseHeaders directive is needed when the script sends the header (in mod_perl 1.0, this was given as PerlSendHeader ON).
PerlOptions +ParseHeaders
PerlSendHeader ON)
As an illustration of how mod_perl 2.0 addresses the issues raised in the discussion of issues in multithread win32 concerning the threading limitations of mod_perl 1.0 on Win32, consider the printenv script above with the sleep(10) line uncommented. Using the Apache benchmarking tool ab of the Apache 2.0 Win32 distribution:
printenv
sleep(10)
ab
C:\Apache2\bin> ab -n 5 -c 5 http://localhost/perl/printenv
to make 5 concurrent requests, we find the following results. For mod_perl 1.0/Apache 1.3:
Server Software: Apache/1.3.23 Concurrency Level: 5 Time taken for tests: 50.51972 seconds Complete requests: 5 Failed requests: 0 Requests per second: 0.10 [#/sec] (mean) Time per request: 50.052 [ms] (mean) Time per request: 10.010 [ms] (mean, across all concurrent requests) Transfer rate: 0.14 [Kbytes/sec] received
while for mod_perl 2.0/Apache 2.0:
Server Software: Apache/2.0.36 Concurrency Level: 5 Time taken for tests: 1.81555 seconds Complete requests: 5 Requests per second: 4.62 [#/sec] (mean) Time per request: 1.082 [ms] (mean) Time per request: 0.216 [ms] (mean, across all concurrent requests) Transfer rate: 7.40 [Kbytes/sec] received
The dramatic difference is due to the fact that in Apache 1.3/mod_perl 1.0 a given request has to finish (taking essentially 10 seconds, due to the sleep(10) call) before the next request is processed, whereas on Apache 2.0/mod_perl 2.0 the requests are processed as they arrive.
As you will discover, there is much to mod_perl beyond simple speed-up of cgi scripts. Here is a simple Hello, World example that illustrates the use of mod_perl as a content handler. Create a file Hello.pm as follows:
package Apache::Hello; use strict; use Apache::RequestRec (); # for $r->content_type use Apache::RequestIO (); # for $r->puts use Apache::Const -compile => ':common'; sub handler { my $r = shift; my $time = scalar localtime(); my $package = __PACKAGE__; $r->content_type('text/html'); $r->puts(<<"END"); <HTML><BODY> <H3>Hello</H3> Hello from <B>$package</B>! The time is $time. </BODY></HTML> END return Apache::OK; } 1;
and save it in, for example, the C:/Perl/site/lib/Apache2/Apache/ directory. Next put the following directives in C:/Apache2/conf/httpd.conf:
PerlModule Apache::Hello <Location /hello> SetHandler modperl PerlResponseHandler Apache::Hello </Location>
With this, calls to
http://localhost/hello
will use Apache::Hello to deliver the content.
Apache::Hello
The directions for installing mod_perl 2.0 on Win32, the mod_perl documentation, http://perl.apache.org/, http://take23.org/, http://httpd.apache.org/, and http://www.activestate.com/. Help on setting up and configuring mod_perl 2.0 can be found by subscribing to the mod_perl mailing list, details of which are at http://perl.apache.org/.
Maintainer is the person(s) you should contact with updates, corrections and patches.
Randy Kobes <randy@theoryx5.uwinnipeg.ca>
Only the major authors are listed above. For contributors see the Changes file.
To install mod_perl, copy and paste the appropriate command in to your terminal.
cpanm
cpanm mod_perl
CPAN shell
perl -MCPAN -e shell install mod_perl
For more information on module installation, please visit the detailed CPAN module installation guide.