Linux Online
[ Register ]

[ Applications ]
[ Documentation ]
[ Distributions ]
[ Download Info ]
[ General Info ]
[ Book Store ]
[ Courses ]
[ News ]
[ People ]
[ Hardware ]
[ Vendors ]
[ Projects ]
[ Events ]
[ User Groups ]
[ User Area ]

Building Embedded Linux Systems

[ About Us ]
[ Home Page ]
[ Advertise ]

Advanced Linux Course

Installation of mod_perl

mod_perl is a way of using Perl to interact directly with the Apache webserver. The mod_perl package basically embeds the Perl interpreter in the webserver so things work faster. If you're a Perl hacker, you'll definitely notice the performance boost with an Apache + mod_perl system.

First, we'll pick up mod_perl 1.x. Since we've used Apache 1.3x, mod_perl 2.0 will not work with it as it's designed for Apache 2.0. But just like Apache 1.3x, though it's not the newest available version, it's the most widely used and it's still well-maintained. You can get the package at http://perl.apache.org/.

Though it goes without saying, you'll need to have Perl itself installed. It's also a good idea to have your perl modules up-to-date before you start the configuration and installation of mod_perl. Issue this command to update your system's perl modules:

perl -MCPAN -e 'install("Bundle::Apache")'

Now you're ready to start the configuration process. Issue the command:

perl Makefile.PL USE_APXS=1 \ 
WITH_APXS=/usr/local/apache/bin/apxs EVERYTHING=1

If everything went well with that, (and there's no reason it couldn't) you can issue this command:

make test

and then:

make

This will install the mod_perl files to their appropriate directories. It will also modify the httpd.conf file so Apache can use mod_perl. It will add lines directly after the ones previously added by the PHP installation:

LoadModule php5_module        libexec/libphp5.so
LoadModule perl_module        libexec/libperl.so

and:

AddModule mod_php5.c
AddModule mod_perl.c

Now, restart Apache. You can do the following to make sure that mod_perl is correctly configured and installed. If you've got the text mode browser Lynx, start it with the following command:

lynx -mime_header http://your-server | grep Server

You should see the following:

Server: Apache/1.3.31 (Unix) mod_perl/1.29 PHP/5.0.2 
mod_ssl/2.8.20 OpenSSL/0.9.7d

Now we need a place where our mod_perl scripts are going to run from. To create our own special mod_perl space, add the following code to your httpd.conf:

Alias /perl/  /usr/local/apache/perl-bin/

PerlModule Apache::Registry
  <Location /perl/>
      SetHandler perl-script
      PerlHandler Apache::Registry
      Options +ExecCGI
      PerlSendHeader On
      allow from all
  </Location>

For this, I created the directory 'perl-bin' in /usr/local/apache/. You can create this directory in a different place and give it any name you'd like. Just remember to change the 'Alias' line. After you've done this, you can try out your mod_perl installation with a script like this:

print "Content-type: text/plain\n\n";
print "OMG! mod_perl works!\n";

Create this script using 'vi' or your favorite text editor. Make it executable (chmod 755 script.pl). Restart Apache and point your browser at the script. You should now see the message:

OMG! mod_perl works!

You've now got a working mod_perl installation on your machine.



Comments: feedback (at) linux.org
Advertising: banners (at) linux.org
Copyright Linux Online Inc.
Compilation ©1994-2008 Linux Online, Inc.
All rights reserved.