Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

How to configure mod_perl?

by rifat (Initiate)
on Jun 17, 2011 at 13:43 UTC ( #910154=perlquestion: print w/replies, xml ) Need Help??

rifat has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to use mod_perl2 with apache2 in Ubuntu 10.04 LTS. From m0d_perl guide, I added the following lines between <VirtualHost> tag.

Alias /perl/ /var/www/perl/
<Location "/var/www/perl/"> SetHandler perl-script PerlResponseHandler ModPerl::Registry PerlOptions +ParseHeaders Options +ExecCGI Order allow,deny Allow from all </Location>

Theoretically, when I put a perl script on '/var/www/perl' directory and chmod it, the script should be executed when accessed from http://localhost/perl/ But the browser prompt me to download it. How can I solved this problem?I asked the question after googling for about 1 week. I tried all possible combinations, but none worked. How can I get around this problem?

Thank you

Replies are listed 'Best First'.
Re: How to configure mod_perl
by moritz (Cardinal) on Jun 17, 2011 at 13:56 UTC
      Not required, it will treat every file under directory as perl
Re: How to configure mod_perl
by wfsp (Abbot) on Jun 17, 2011 at 14:17 UTC
    Have you loaded mod_perl?
    LoadModule perl_module modules/
      Yes. It's written on /etc/apache2/mods-enabled/perl.load. It is loaded by the 'Include /etc/apache2/mods-enabled/*.load' command. Though there is no perl.conf file, I don't think it is necessary, as I wrote the statements on the main config file.
Re: How to configure mod_perl
by davido (Cardinal) on Jun 17, 2011 at 16:09 UTC

    This may seem obvious, but have you restarted the Apache server? (Sometimes it's the simple things that trip us up.) Anytime a configuration file has been changed the server needs to restart to catch the changes.


      I have to do it very frequently now-a-days, so I rarely forget to do it. But, you're right, little things can be very tricky. And I think the problem which I'm facing now must be also a little one, but I'm yet to find a out.

Re: How to configure mod_perl
by rev_1318 (Chaplain) on Jun 17, 2011 at 16:45 UTC
    I thing you're mistaking the use off Location vs. Directory. Your directive should read:
    <Directory "/var/www/perl"> .... </Directory>
    <Location "/perl"> ... </Location>
    (assuming your DocumentRoot is /var/www.)


      Doing it makes the browser say, the file cannot be found. I think it means the alias has not been recognized by apache.
Re: How to configure mod_perl?
by zek152 (Pilgrim) on Jun 17, 2011 at 19:45 UTC

      Though I've seen the posts before, this time they worked for me. :)

      The mistake was silliest one possible. I didn't put two '\n's at the end of print "Content-type: text/html"; It costed me so many hours. I was so determined that the fault is on configuration file that I never bothered to scrutinize the scripts. By the way, I never thought omitting these characters would stop the script from being executed. CGI programming is very strict, I must say. Thank you zek152 and everybody else

Re: How to configure mod_perl?
by martell (Hermit) on Jun 17, 2011 at 21:48 UTC

    I've got a working mod_perl installation on Ubuntu 10.O4. I've done the following things to get it working.

    First i've created a file "/etc/apache2/site-available/yoursite" with following configuration:"

    <VirtualHost *:80> ServerName yoursite ServerAdmin webmaster@localhost DocumentRoot /var/www/yoursite PerlModule ModPerl::Registry <Location /> SetHandler perl-script PerlResponseHandler ModPerl::Registry Options +ExecCGI </Location> ErrorLog /var/log/apache2/error.log # Possible values include: debug, info, notice, warn, error, c +rit, # alert, emerg. LogLevel warn CustomLog /var/log/apache2/access.log combined </VirtualHost>

    Note that i create a virtual host with a given name. To make sure that the site is visible, add a following line in your "/etc/hosts": yoursite.localdomain yoursite

    Now create the directory "/var/www/yoursite", make sure it is readable by user "www-data", and create a file "" with following content:

    use Apache2::RequestUtil; my $r = Apache2::RequestUtil->request; $r->content_type("text/html"); $r->print("mod_perl rules!");

    Note i've removed the "$r->send_http_header" line. It is not a valid method anymore under mod_perl2.

    Restart your apache server.

    This should give, when going to "http://yoursite/", the text "mod_perl rules!".

    Hope this helps.

    Kind regards


      And as rifat mentionned, be sure to have mod_perl loaded. If the file /etc/apache2/mods-enabled/perl.load does not exist, run a2enmod perl (it's better than a symlink), and reload Apache.
Re: How to configure mod_perl
by Anonymous Monk on Jun 17, 2011 at 13:55 UTC
    But the browser prompt me to download it. How can I solved this problem?

    What gets downloaded?

      The .pl file.

        Are you sure? Did you look inside and see use strict; ... your program?
Re: How to configure mod_perl
by Anonymous Monk on Jun 17, 2011 at 13:56 UTC
    Are you using You need PerlOptions +SetupEnv
      Adding +SetupEnv makes no difference.
Re: How to configure mod_perl?
by rifat (Initiate) on Jun 17, 2011 at 17:25 UTC

    Thanks everyone for your responses. This is my first post on any open forum about a computer and programming related issue. I think you guys can help me to make a way into the world of perl. Your helps will be gratefully appreciated.

    If any of you have a working apache with mod_perl setup in Ubuntu or Debian, kindly send me the changes you made for running mod_perl. Even if you've done it in any rpm based distro, the necessary parts of httpd.conf will also definitely help.

    Do anyone of you think that is a bug specific for Ubuntu?

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://910154]
Approved by Corion
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (6)
As of 2022-06-28 19:32 GMT
Find Nodes?
    Voting Booth?
    My most frequent journeys are powered by:

    Results (92 votes). Check out past polls.