≡ Menu

UNIX / Linux: How to Install and Configure mod_perl for Apache 2

If you are running any web based open source application that is written in perl, you should be using mod_perl with Apache instead of running it as CGI. mod_perl is way faster than running a web application using CGI.

This article explains how to install mod_perl on Apache 2.

First, install Apache 2, if you don’t have it already.

1. Download mod_perl

Download mod_perl from perl.apache.org as shown below.

# cd ~

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

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

# cd mod_perl-2.0.4/

2. Configure mod_perl with Apache2

Specify the location of your Apache 2 installation to the mod_perl as shown below.

# perl Makefile.PL MP_APXS=/usr/local/apache2/bin/apxs

Reading Makefile.PL args from @ARGV
  MP_APXS = /usr/local/apache2/bin/apxs
no conflicting prior mod_perl version found - good.
Configuring Apache/2.2.15 mod_perl/2.0.4 Perl/v5.8.8
Checking if your kit is complete...
Looks good
Writing Makefile for ModPerl
Writing Makefile for ModPerl::XS
Writing Makefile for mod_perl2

Note: If you encounter the “libgdbm.so was not found. You could just symlink it to /usr/lib/libgdbm.so.2.0.0” message, install the gdbm-devel package as shown below.

# rpm -ivh gdbm-devel-1.8.0-26.2.1.i386.rpm

# rpm -qa | grep gdbm
gdbm-devel-1.8.0-26.2.1
gdbm-1.8.0-26.2.1

At this stage, the mod_perl is still not installed, which you can verify by checking the contents of the Apache 2 modules directory.

# /usr/local/apache2/bin/apxs -q LIBEXECDIR
/usr/local/apache2/modules

# ls -l /usr/local/apache2/modules/
total 16512
-rw-r--r-- 1 root root     9083 May 18 09:59 httpd.exp
-rwxr-xr-x 1 root root 16871365 May 19 03:44 libphp5.so

3. Make and install the mod_perl

First, do a make test, to make sure everything looks good.

# make test

t/special_blocks.t ... ok
All tests successful.
Files=20, Tests=84, 14 wallclock secs ( 0.17 usr  0.06 sys +  9.10 cusr  1.46 csys = 10.79 CPU)
Result: PASS

Finally, do a make install to install the mod_perl on Apache2.

# make install

Installing /usr/share/man/man3/Apache::TestReport.3pm
Installing /usr/share/man/man3/ModPerl::Global.3pm
Installing /usr/bin/mp2bug
Appending installation info to /usr/lib/perl5/5.8.8/i386-linux-thread-multi/perllocal.pod
+--------------------------------------------------------------+
|                                                              |
| For details on getting started with mod_perl 2, see:         |
|                                                              |
|   http://perl.apache.org/docs/2.0/user/intro/start_fast.html |
|                                                              |
|                                                              |
| Found a bug?  File a bug report:                             |
|                                                              |
|   http://perl.apache.org/bugs/                               |
|                                                              |
+--------------------------------------------------------------+

4. Modify httpd.conf and Restart Apache

Modify the httpd.conf to load the mod_perl.so as shown below

# grep perl /usr/local/apache2/conf/httpd.conf
LoadModule perl_module modules/mod_perl.so

Restart the Apache.

# /usr/local/apache2/bin/apachectl restart

5. Verify mod_perl is installed

If everything goes smoothly, you’ll see mod_perl.so under the apache modules directory.

# ls -l /usr/local/apache2/modules/
total 17752
-rw-r--r-- 1 root root     9083 May 18 09:59 httpd.exp
-rwxr-xr-x 1 root root 16871365 May 19 03:44 libphp5.so
-rwxr-xr-x 1 root root  1264743 Jun 21 10:01 mod_perl.so

Apache error_log will also show that mod_perl is installed as shown below.

# tail /usr/local/apache2/logs/error_log
[notice] Apache/2.2.15 (Unix) PHP/5.3.2 mod_perl/2.0.4 Perl/v5.8.8 configured
Add your comment

If you enjoyed this article, you might also like..

  1. 50 Linux Sysadmin Tutorials
  2. 50 Most Frequently Used Linux Commands (With Examples)
  3. Top 25 Best Linux Performance Monitoring and Debugging Tools
  4. Mommy, I found it! – 15 Practical Linux Find Command Examples
  5. Linux 101 Hacks 2nd Edition eBook Linux 101 Hacks Book

Bash 101 Hacks Book Sed and Awk 101 Hacks Book Nagios Core 3 Book Vim 101 Hacks Book

Comments on this entry are closed.

  • David Yingling January 11, 2011, 2:51 pm

    mod_perl has mostly been superseded by Plack and PSGI these days. Plack and PSGI are Perl’s knock offs or Ruby’s Rack and Python’s WSGI. Plack runs on most web servers and supports a standalone server for development. Check it out at http://plackperl.org/

  • Jitendra April 11, 2011, 8:47 am

    Hi,
    I am trying to install http server with mod_perl on RHEL 5 box following your instructions but facing following error.

    1. Installed httpd server 2.2.17. I can see /usr/local/apache2 directory.
    2. Downloaded mod_perl from location, you specified. But when I try to run following command
    perl Makefile.PL MP_APXS=/usr/local/apache2/bin/apxs

    I get this error.

    Reading Makefile.PL args from @ARGV
    MP_APXS = /usr/local/apache2/bin/apxs
    no conflicting prior mod_perl version found – good.
    [ error] ‘/usr/local/apache2/bin/apxs -q INCLUDEDIR’ failed:
    [ error] /usr/local/apache2/bin/apxs: line 18: require: command not found
    /usr/local/apache2/bin/apxs: line 19: use: command not found
    /usr/local/apache2/bin/apxs: line 20: package: command not found
    /usr/local/apache2/bin/apxs: line 26: syntax error near unexpected token `(‘
    /usr/local/apache2/bin/apxs: line 26: `my %config_vars = ();’
    [ error] Unable to determine server version, aborting.
    [ error] Invalid MP_APXS specified?

    Could you please help me. and what is going wrong here?

    Thanks a lot
    Jitendra

  • Sam February 8, 2012, 4:13 pm

    I had to run make as root, make test as regular user (it told me the test had to be done by an “unprivileged” user, and then run make install as root.