Configuring mod_perl and apache

mod_perl from scratch in 8 simple steps

When I installed mod_perl for the first time, or apache-perl which it was called back then, it was hard.

The instructions for new users on perl.apache.org make assumptions about where apache is installed which do not coincide with how Debian works, and they do not show you how to get mod_perl working with ssl, and last but not least annoying - the instructions assume that you need to compile mod_perl, which you definitely do not need if you use Debian.

In short, if you want to use mod_perl on a debian server, then these instructions are what you really need.

Install mod_perl

apt-get install libapache2-mod-perl2 apache2 libapache2-request-perl

Enable mod_perl and ssl

a2enmod perl
a2enmod ssl

Create a new site

Copy the default ssl-site

cp /etc/apache2/sites-available/default-ssl.conf /etc/apache2/sites-available/001-ssl.conf

Add directives for mod_perl

Add the following lines just below the DocumentRoot directive

PerlRequire /var/www/perl/include-my-dirs.pl
PerlOptions +GlobalRequest

<Location /my-testbed>
    SetHandler perl-script
    PerlResponseHandler testbed
</Location>

Enable the new site

a2ensite 001-ssl.conf

Add the files and directories needed

In the directives for mod_perl above, we refer to two files: /var/www/perl/include-my-dirs.pl and testbed.pm (for the latter, ".pm" is implicit), but we have not created them yet.

First, create the directory /var/www/perl.

mkdir /var/www/perl

Second, put the following in /var/www/perl/include-my-dirs.pl

use lib qw(/var/www/perl);
1;

Third, put this in /var/www/perl/testbed.pm

package testbed;

use strict;
use warnings;
use Apache2::Request;
use Apache2::RequestUtil;
use Apache2::RequestRec ();
use Apache2::RequestIO ();
use Apache2::Const -compile => qw(OK);

sub handler {
  print "<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='utf-8'>
</head>
<body>
Hello Wörld
</body>
</html>
";
  return Apache2::Const::OK;
}
1;

Restart apache2

service apache2 reload

Browse to your shiny new mod_perl instance at https://localhost/my-testbed

comments powered by Disqus


Back to the index

Blog roll

R-bloggers, Debian Weekly
Valid XHTML 1.0 Strict [Valid RSS] Valid CSS! Emacs Muse Last modified: oktober 12, 2017