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

I'm trying to set up mod_perl on a Ubuntu 9.04 box. I think that I have mod_per installed correctly, but I am having trouble configuring the system to use mod_perl.

Efforts so far:

1) apt-get install of libapache2-mod-perl2, libapache2-mod-perl2-dev, libapache2-mod-perl2-doc, perl-doc.

2) Not knowing where and what documentation came with my libapache2-mod-perl2-doc I did some searching. I found a helpful looking file name at /usr/share/doc/libapache2-mod-perl2-doc/api/ModPerl/PerlRun.pod. I don't know for sure if this is where I should be, but by running "perldoc PerlRun" in this directory I got a helpful looking display.

3) Useful looking info from the perldoc:
# httpd.conf PerlModule ModPerl::PerlRun Alias /perl-run/ /home/httpd/perl/ <Location /perl-run> SetHandler perl-script PerlResponseHandler ModPerl::PerlRun PerlOptions _ParseHeaders Options +ExecCGI </Location>
My system has an empty /etc/apache2/httpd.conf but it is using apache2.conf. Thus, I used apache2.conf. Also, my perl code (code that runs well on another mod_perl machine) is at /var/www/perl. Thus, what I added to apache2.conf was
PerlModule ModPerl::PerlRun Alias /perl/ /var/www/perl/ <Location /perl> SetHandler perl-script PerlResponseHandler ModPerl::PerlRun PerlOptions _ParseHeaders Options +ExecCGI </Location>
Reset server via "/etc/init.d/apache2 reset".

Attempts to access the script from a browser yielded a "is of type text/x-perl, and SeaMonkey does not know how to handle this file type" message. I can use one of the options to view my script file. Thus, my URL is hitting the correct file but Apache returning the text of the script rather than executing it.

4) Attempting to do something useful I attempt to get status information using the browser and the URL http://127.0.0.1/perl/perl-status. I got a "Not Found" error message with a page footer of "Apache/2.2.11 (Ubuntu) mod_perl/2.0.4 Perl/v5.10.0 Server at 127.0.0.1 Port 80". Thus, I think mod_perl is installed correctly but Apache configuration files are not set up to use it. (I don't know why perl-status didn't work as shown in my book.)

5) I changed the ownership and group of the perl directory and it's contents to www-data. I also changed permissions so Owner, Group and All can execute the file and the directory. Reset Apache server. Same "text returned" issue.

I have done some Googling but I find many different and sometimes "conflicting sounding" bits of configuration advice.

Any suggestions? It seems like there should be a simple step-by-step document for setting up mod_perl, but so far the only one I found doesn't seem to be good enough.

Thanks,
Bruce

Replies are listed 'Best First'.
Re: mod_perl configuration of Apache2
by gmargo (Hermit) on Dec 12, 2009 at 18:18 UTC

    I was able to get it to work using the same Ubuntu 9.04 (jaunty) configuration, using the apache2-mpm-prefork model. (Hooray for virtual machines!)

    I added the snippet you provided to /etc/apache2/httpd.conf, which is ok since that file is included by /etc/apache2/apache2.conf. I fixed the one typo, changing "PerlOptions _ParseHeaders" to "PerlOptions +ParseHeaders".

    Then I put the following "Hello World" program in the /var/www/perl directory, named hello.pl. I was surprised that I did not have to make it executable.

    #!/usr/bin/perl print "Content-type: text/html\r\n\r\n"; print "<HTML>\n"; print "<HEAD><TITLE>Hello World!</TITLE></HEAD>\n"; print "<BODY>\n"; print "<H2>Hello World!</H2>\n"; print "</BODY>\n"; print "</HTML>\n"; exit (0);

    And after stopping/starting the server, I got the expected output. I did do a full stop then start on the server. A restart will warn about the typo but not stop the server from executing. Perhaps this is your problem.

    I didn't do anything special with permissions:

    root@jackalope 680# ls -ld /var /var/www drwxr-xr-x 15 root root 4096 Dec 12 09:11 /var drwxr-xr-x 3 root root 4096 Dec 12 09:41 /var/www root@jackalope 681# ls -lRA /var/www /var/www: total 8 -rw-r--r-- 1 root root 45 Dec 12 09:11 index.html drwxr-xr-x 2 root root 4096 Dec 12 09:58 perl /var/www/perl: total 4 -rw-r--r-- 1 root root 232 Dec 12 09:58 hello.pl
      Thanks for the reply.

      The machine that I was working on is at work and I will not have access to it again until Monday. Thus, I am trying to set up mod_perl on a home machine. Hopefully what I learn at home this weekend will help me at work on Monday morning.

      I don't know if the typo was present in apache2.conf or if it was introduced as I was working on my posting. I'll check that early Monday. By following the provided guidance I added the lines to my home machine. This is a machine that I tried to set up mod_perl on about a year ago (unsuccessfully) and therefore I don't have a "clean install" at home.

      At home I am getting perl execution, but it is CGI perl and not mod_perl. I know this due to a modified version of the program from page 76 of "MySQL and Perl for the Web" by Paul DuBois (ISBN 0-7357-1054-6). The test program is:
      #!/usr/bin/perl -w # FILE: cgi_or_mod-perl.pl use strict; use warnings; use CGI qw(:standard); print header(), start_html ("CGI or mod-perl test"); print "If 'GATEWAY_INTERFACE = CGI/1.1' then regular CGI.<BR>"; print "If 'GATEWAY_INTERFACE - CGI-Perl/1.1' then mod-perl.<BR>"; print "<BR>"; print "========== TESTING ABILITY OF A PERL SCRIPT TO ACCESS ENVIRONME +NT VARIABLES ========<BR>"; print "REMOTE_ADDR = $ENV{REMOTE_ADDR}<BR>"; print "REMOTE_PORT = $ENV{REMOTE_PORT}<BR>"; print "HTTP_REFERER = $ENV{HTTP_REFERER}<BR>"; print "<BR>"; print "========== FULL DUMP OF ENVIRONMENT VARIABLES ==========<BR>"; print map { "$_ = $ENV{$_}<BR>\n"} sort(keys(%ENV)); print "<BR>"; print end_html(); exit (0);
      The test code worked well years ago when I used it to set up mod_perl on Debian machines (that also was a pain to get the mod_perl to run).

      My current status is:

      WORK COMPUTER - Current status is a mystery but the above discovered typo is a possibility. I'll know more Monday morning.

      HOME COMPUTER - When a browser hits a perl script the script will execute and the "expected" results will be returned. BUT, THIS WAS CGI PERL AND NOT MOD_PERL. The cause of this is still a mystery and I am working on it.

      Thanks,
      Bruce
        When I run the script from my previous posting I get the following:
        If 'GATEWAY_INTERFACE = CGI/1.1' then regular CGI. If 'GATEWAY_INTERFACE - CGI-Perl/1.1' then mod-perl. ========== TESTING ABILITY OF A PERL SCRIPT TO ACCESS ENVIRONMENT VARI +ABLES ======== REMOTE_ADDR = 127.0.0.1 REMOTE_PORT = 45469 HTTP_REFERER = ========== FULL DUMP OF ENVIRONMENT VARIABLES ========== DOCUMENT_ROOT = /var/www GATEWAY_INTERFACE = CGI/1.1 HTTP_ACCEPT = text/xml,application/xml,application/xhtml+xml,text/html +;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5 HTTP_ACCEPT_CHARSET = ISO-8859-1,utf-8;q=0.7,*;q=0.7 HTTP_ACCEPT_ENCODING = gzip,deflate HTTP_ACCEPT_LANGUAGE = en-us,en;q=0.5 HTTP_CONNECTION = keep-alive HTTP_HOST = 127.0.0.1 HTTP_KEEP_ALIVE = 300 HTTP_USER_AGENT = Mozilla/5.0 (X11; U; Linux i686 (x86_64); en-US; rv: +1.8.1.6) Gecko/20070802 SeaMonkey/1.1.4 MOD_PERL = mod_perl/2.0.2 MOD_PERL_API_VERSION = 2 PATH = /usr/local/bin:/usr/bin:/bin QUERY_STRING = REMOTE_ADDR = 127.0.0.1 REMOTE_PORT = 45469 REQUEST_METHOD = GET REQUEST_URI = /perl/cgi_or_mod-perl.pl SCRIPT_FILENAME = /var/www/perl/cgi_or_mod-perl.pl SCRIPT_NAME = /perl/cgi_or_mod-perl.pl SERVER_ADDR = 127.0.0.1 SERVER_ADMIN = webmaster@localhost SERVER_NAME = 127.0.0.1 SERVER_PORT = 80 SERVER_PROTOCOL = HTTP/1.1 SERVER_SIGNATURE = Apache/2.0.55 (Ubuntu) PHP/4.4.2-1build1 mod_perl/2.0.2 Perl/v5.8.7 Se +rver at 127.0.0.1 Port 80 SERVER_SOFTWARE = Apache/2.0.55 (Ubuntu) PHP/4.4.2-1build1 mod_perl/2. +0.2 Perl/v5.8.7

        Based upon the DuBois text I conclude that mod_perl is installed but not being used when the perl code is executed.

        Bruce
Re: mod_perl configuration of Apache2
by Anonymous Monk on Dec 12, 2009 at 02:55 UTC
    Why not check the log files?
      There have been several times that I checked and did not see an error. That made since to me since, from the servers point of view, I don't think there was a server error. The server was not correctly told to run the script through mod_perl and therefore the script text got sent to the browser just as a .txt file would have.