Installing Apache2/Modperl on Ubuntu 12.04

apt-get install apache2
apt-get install libapache2-mod-perl2
apt-get install perl-debug
apt-get install libapache2-mod-perl2-dev
apt-get install  libapache2-request-perl libdatetime-perl 

Edit /etc/apache2/sites-available/default, add:

        <Location /perl/>
                SetHandler perl-script
                PerlHandler ModPerl::PerlRun
                Options ExecCGI
                PerlSendHeader On
                allow from all
        </Location>

Install the CGI module:

cpan install CGI

Create a directory /var/www/perl. Add a script, for example:

#!/usr/bin/perl

use CGI;                             # load CGI routines
$q = CGI->new;                        # create new CGI object
print $q->header,                    # create the HTTP header
      $q->start_html('hello world'), # start the HTML
      $q->h1('hello world'),         # level 1 header
      $q->end_html;                  # end the HTML

Call it something like hello.pl. Try to access http://server/perl/hello.pl, everything should work correctly.

4 thoughts on “Installing Apache2/Modperl on Ubuntu 12.04

  1. Okay, I have this AMD virtual hosts set up, so when I go into mystify/perl I have two scripts, neither work…I followed this to the T
    Since my vhost is at /var/www/site1 would I have to edit Location /perl to /location /site1/perl ?

  2. apt-get install apache2 libapache-mod-perl2Reading package lists… Done
    Building dependency tree
    Reading state information… Done
    E: Unable to locate package libapache-mod-perl2
    please help me!!!!!!!!!!!!!!!!

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>