Mod_Perl.. Configuring and troubleshooting..

Mod_Perl

1. What is mod_perl ?

2. Working of mod_perl.

3. Advantage & Disadvantages of mod_perl.

4. Downloading and Installation.

5. Configuration.

6. Some common errors.

What is mod_perl ?

Mod_perl is an important module in apache/Perl

integration project, which brings together the full power of the Perl programming language and the Apache Web server.

Modules are normally written in C, modifying/editing it can be hard work. mod_perl is a module which lets you do all of these things, and more, using Perl which makes the development much quicker than C.

As Apache is the most popular Web server on the Internet and mod_perl is one of the most popular modules for extending it.

How It Works

Working of Mod_perl

When Apache receives a request for a static HTML file, it can serve the request directly by opening the file and writing it out over the network to the client.

But for programs, such as the Perl cgi-bin, they arent processed by Apache itself. Instead, Apache starts up Perl as an external process and returns its output to the requesting client. Thus by invoking an external program taxes the Web server host and also introduces some delay into serving the request. This overhead is incurred repeatedly as script requests arrive because Apache starts up a new Perl process to handle each one.

An alternative to running scripts using external processes is to make the script handler part of Apache itself. In the case of Perl scripts, we use the mod_perl module to embed the Perl interpreter into Apache. The result is that Apache gains the capability to execute Perl scripts directly.

Advantages of using mod_perl

  • The real power of mod_perl is the ability for you to directly use all of the Apache API from Perl.
  • Power and speed.(Apache can execute Perl scripts more quickly because it need not start up or wait for standalone external processes)
  • There are big savings in startup and compilation times.(A script-execution process nvolves examining the script and compiling it and then running it. When Perl runs as part if Apache, the compiled script remains loaded in memory and is immediately available for execution. It need not be recompiled if the server receives another request for it.)
  • There is very little run-time overhead. In particular, under mod_perl there is no need to start a separate process per request, as is oftendone with other web-server extensions.
  • mod_perl allows you to configure your Apache server and handlers in Perl (using the PerlSetVar directive and the <Perl> sections). We can even define your own configuration directives!

Disadvantages of using mod_perl

  • Apache installation and configuration becomes more involved.
  • Embedding the Perl interpreter into Apache causes httpd processes to become larger and take more memory. We may need necessary to perform some configuration tuning.
  • mod_perl scripts always run under the user and group IDs of the httpd process. You cant execute them with the privileges ofanother user or group using the suEXEC mechanism the way you can with standalone scripts.

Most of the disadvantages are one-time issues.Apache configuration is more complicated with mod_perl, but after getting things set up the we can leave our configuration alone.

Downloading the package

We can get source and binary mod_perl distributions from the url

http://perl.apache.org/download/index.html

Link to download mod_perl-2.0.

http://perl.apache.org/dist/mod_perl-2.0-current.tar.gz

We can download the package using utils like wget etc.
Prerequisites
Before building mod_perl 2.0 you need to have its prerequisites installed. If you dont have them, download and install them first,Otherwise proceed directly to the mod_perl building instructions.

The mod_perl 2.0 prerequisites are:

* Apache (Apache 2.0 is required. mod_perl 2.0 does not work with Apache 1.3.)

* Perl (Requires at least Perl version 5.6.1)

Installing mod_perl from Source

First download the mod_perl source.

* Download from Stable Release :http://perl.apache.org/download/

Or from your favorite CPAN mirror.Open the package with:

# tar -xvzf mod_perl-2.x.x.tar.gz

Configuring mod_perl

Like any other Perl module, mod_perl is configured via the

Makefile.PL file, but requires one or more configuration options:

# cd modperl-2.x.x

# perl Makefile.PL <options>

where options is an optional list of key/value pairs

Link for Optional list:

http://perl.apache.org/docs/2.0/user/install/install.html#mod_perl_Build_Options

Before you proceed, make sure that Apache 2.0 has been built and installed. mod_perl cannot be built before that.

Example

# tar -xvzf mod_perl-2.0-current.tar.gz

# cd mod_perl-2.0.4

# perl Makefile.PL MP_APXS =/usr/local/apache/bin/apxs EVERYTHING=1

# make

# make install

Configuration

Once you have mod_perl installed you will need to configure it in your httpd.conf by adding the following configuration options:LoadModule perl_module modules/mod_perl.so

PerlRequire /path/to/perl/libs/startup.pl

Server Launch and Shutdown

Start:

# /usr/local/apache/bin/apachectl start

# tail -f usr/local/apache/logs/error_log

[Tue May 25 09:24:28 2004] [notice] Apache/2.0.50-dev (Unix) mod_perl/1.99_15-dev Perl/v5.8.4 mod_ssl/2.0.50-dev OpenSSL/0.9.7c DAV/2 configured resuming normal operations

Stop:

# /usr/local/apache/bin/apachectl stop

Registry Scripts

To enable registry scripts add the following to httpd.conf:

Alias /perl/ /home/httpd/httpd-2.0/perl/

<Location /perl/>

SetHandler perl-script

PerlResponseHandler ModPerl::Registry

PerlOptions +ParseHeaders

Options +ExecCGI

Order allow,deny

Allow from all

</Location>

Some common Issues

  • No rule to make target CORE/config.h

If while running make you get a message:

make: *** No rule to make target

`/usr/lib/perl5/5.8.3/i386-linux/CORE/config.h,needed by `Makefile. Stop.

Solution:

That means that your Perl installation is incomplete. Usually this is the case on package based distros, where perl is split across multiple packages.Usually you need to install the Perl-devel package to be able to build any other Perl modules that include XS extensions.

  • syntax error at /dev/null line 1, near line arguments:

Error

syntax error at /dev/null line 1, near line arguments:

Execution of /dev/null aborted due to compilation errors. parse: Undefined error: 0

Solution:

There is a chance that your /dev/null device is broken. Try:

# echo > /dev/null

Alternatively you should try to remove this special file and recreate it:

# rm /dev/null

# mknod /dev/null c 1 3

# chmod a+rw /dev/null

  • Invalid command PerlHandler

Error:

Invalid command PerlHandler

Syntax error on line 393 of /etc/httpd/conf/httpd.conf: Invalid command PerlHandler, perhaps mis-spelled or defined by a module not included in the server configuration [FAILED]

Solution:

This can happen when you have a mod_perl enabled Apache compiled with DSO (generally its an installed RPM or other binary package) but the mod_perl module isnt loaded. In this case you have to tell Apache to load mod_perl by adding:

AddModule mod_perl.c in your httpd.conf.

This can also happen when you try to run a non-mod_perl Apache server using the configuration from a mod_perl server.

  • libexec/libperl.so: open failed: No such file or directory

Error

If when you run the server you get the following error:

libexec/libperl.so: open failed: No such file or directory

Solution:

it probably means that Perl was compiled with a shared library. mod_perl does detect this and links the Apache executable to the Perl shared library (libperl.so).

First of all make sure you have Perl installed on the machine, and that you have

libperl.so in <perlroot>/<version>/<architecture>/CORE.

For example in /usr/local/lib/perl5/5.00503/sun4-solaris/CORE.

Then make sure that directory is included in the environment variable LD_LIBRARY_PRELOAD. Under normal circumstances, Apache should have the path configured at compile time, but this way you can override the library path.

  • Cant locate object method get_handlers

Error

Cant locate object method get_handlers via package Apache

Solution:

You need to rebuild your mod_perl with stacked handlers,

i.e. PERL_STACKED_HANDLERS=1 or more simply EVERYTHING=1.

Article Authored by Anand V Kammath

Author, Anand V Kammath, is a Systems Engineer with SupportPRO. Anand specializes in Level 2 and Level 3 Linux / Windows Administration. SupportPRO offers 24X7 technical support services to Web hosting companies and service providers.

Leave a Reply