Recipe 2.4 Installing mod_perl on a Unixish System


You want to install the mod_perl scripting module to allow better Perl script performance and easy integration with the web server.


Download and unpack the mod_perl source package from Then use the following command:

% perl Makefile.PL \  >     USE_APXS=1 \  >     WITH_APXS= /usr/local/apache/bin/apxs \  >     EVERYTHING=1 \  >     PERL_USELARGEFILES=0  % make  % make install 

Restart your server.


mod_perl is quite a complex module, and there are several different ways to add it to your server. This recipe is the fastest and lowest-impact one; if it doesn't suit your needs, check the various README.* files in the package directory after unpacking. Because its primary language is Perl rather than C, the installation instructions are significantly different from those for most other modules.

Once you have restarted your server successfully, mod_perl should be available and configured as part of it. You can test it by making some changes to the httpd.conf file, adding a few scripts, and seeing whether the server processes them correctly. Here is a sample set of steps to test mod_perl's operation.

  1. Create a directory where your mod_perl scripts can live:

    # cd  ServerRoot  # mkdir lib lib/perl lib/perl/Apache 
  2. Create a file named in your server's conf/ directory that will give mod_perl some startup instructions:

    #! /usr/bin/perl BEGIN {     use Apache (  );     use lib Apache->server_root_relative('lib/perl'); } use Apache::Registry (  ); use Apache::Constants (  ); use CGI qw(-compile :all); use CGI::Carp (  ); 1;
  3. Next, create the lib/perl/Apache/ file that will be used for our test:

    package Apache::HelloWorld; use strict; use Apache::Constants qw(:common); sub handler {     my $r = shift;     $r->content_type('text/plain; charset=ISO-8859-1');     $r->send_http_header;     $r->print("Hello, world!  Love, mod_perl.\n");     return OK; } 1;
  4. Next, edit the server's configuration file to add the directives that will enable mod_perl to locate all the pieces it needs, and tell it when to invoke the test script. Add the following lines to the httpd.conf file:

    <IfModule mod_perl.c>     PerlRequire conf/     <Location /mod_perl/howdy>         SetHandler perl-script         PerlHandler Apache::HelloWorld     </Location> </IfModule>
  5. Now restart your server and request the script using http://localhost/mod_perl/howdy.

If your configuration is valid, the response should be a page containing simply the words, "Hello, world! Love, mod_perl."

See Also


  • Writing Apache Modules with Perl and C by Doug MacEachern and Lincoln Stein (O'Reilly)

  • mod_perl Developer's Cookbook by Simon Cozens (O'Reilly)

Apache Cookbook
Apache Cookbook: Solutions and Examples for Apache Administrators
ISBN: 0596529945
EAN: 2147483647
Year: 2006
Pages: 215

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: