For Programmers: Free Programming Magazines  


Home > Archive > PERL CGI Beginners > December 2004 > mod_perl questions









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author mod_perl questions
Greg Donald

2004-12-18, 8:55 pm

I've used Perl off and on for years but I am now trying to work with
mod_perl and I have some questions/issues.


How can I tell if I have mod_perl configured correctly? I installed
it with `emerge mod_perl` on my Gentoo box. I am running Apache2. I
see the line:

Apache/2.0.52 (Gentoo/Linux) mod_perl/1.99_11 Perl/v5.8.5 PHP/5.0.3
Server at destiney.mine.nu Port 80

when I type a nonexistant url. Is that it as far a "complete" mod_perl install?



My apache config contains this:

<IfModule mod_perl.c>
#Provide two aliases to the same cgi-bin directory,
#to see the effects of the 2 different mod_perl modes
#for Apache::Registry Mode
Alias /perl/ /var/www/localhost/perl/
#for Apache::Perlrun Mode
Alias /cgi-perl/ /var/www/localhost/perl/
</IfModule>

<IfModule mod_perl.c>
PerlModule Apache2::ModPerl::Registry
#set Apache::Registry Mode for /perl Alias
# To set subdirectories to use perl set the following
# and comment the orignial:
# <Location ~ "^/perl/.*\.pl$">

<Location "^/perl/*.pl>
SetHandler perl-script
<IfDefine MODPERL2>
PerlResponseHandler Apache2::ModPerl::Registry
</IfDefine>
<IfDefine !MODPERL2>
PerlResponseHandler ModPerl::Registry
</IfDefine>
Options -Indexes ExecCGI
PerlSendHeader On
</Location>

#set Apache::PerlRun Mode for /cgi-perl Alias
<Location /cgi-perl/*.pl>
SetHandler perl-script
PerlResponseHandler ModPerl::PerlRun
Options -Indexes ExecCGI
PerlSendHeader On
</Location>
</IfModule>

So does that mean when I put a .pl script in /perl/ it will be
executed by mod_perl and not #!/usr/bin/perl? Seems to not be the
case since when I remove the #!/usr/bin/perl from the top of a script
it breaks it and I get error like:

[Sat Dec 18 14:43:31 2004] [error] [client 10.0.0.3] (8)Exec format
error: exec of '/var/www/localhost/perl/hello.pl' failed
[Sat Dec 18 14:43:31 2004] [error] [client 10.0.0.3] Premature end of
script headers: hello.pl

in my logs. I read somewhere in the docs when using mod_perl that the
#!/usr/bin/perl is no longer required, so I'm thinking maybe I'm not
done with the apache configuration?


What is the advantage to running mod_perl versus just running perl
scripts out of my cgi-bin ? I suspect there is a performance gain
from to the interpreter already existing in memory or something, but
is there some new syntax I get to use now? Can I now include Perl
code directly into my html?


Thanks for any help you send..


--
Greg Donald
Zend Certified Engineer
http://gdconsultants.com/
http://destiney.com/
Sean Davis

2004-12-18, 8:55 pm

Greg,

You will probably need to read some documentation:

http://perl.apache.org/docs/index.html
http://perl.apache.org/docs/1.0/guide/porting.html

Note that last one is mod_perl-based, not mod_perl2, but it is a reasonable
introduction. Also, the mod_perl book is available online:

http://modperlbook.org/

and is a fantastic resource.

There are, of course, many websites devoted to getting started with
mod_perl.

----- Original Message -----
From: "Greg Donald" <destiney@gmail.com>
To: <beginners-cgi@perl.org>
Sent: Saturday, December 18, 2004 4:35 PM
Subject: mod_perl questions


> I've used Perl off and on for years but I am now trying to work with
> mod_perl and I have some questions/issues.
>
>
> How can I tell if I have mod_perl configured correctly? I installed
> it with `emerge mod_perl` on my Gentoo box. I am running Apache2. I
> see the line:
>
> Apache/2.0.52 (Gentoo/Linux) mod_perl/1.99_11 Perl/v5.8.5 PHP/5.0.3
> Server at destiney.mine.nu Port 80
>
> when I type a nonexistant url. Is that it as far a "complete" mod_perl
> install?


In the documentation are some simple tests you can cut-and-paste to see if
mod_perl is up and running.

> So does that mean when I put a .pl script in /perl/ it will be
> executed by mod_perl and not #!/usr/bin/perl? Seems to not be the
> case since when I remove the #!/usr/bin/perl from the top of a script
> it breaks it and I get error like:


Perl scripts that run under CGI will need to be "handled" by
ModPerl::Registry. There are some specific details about writing scripts
under ModPerl::Registry, mainly relating to the fact that the script is kept
"alive" so that Global variables do not automatically go out of scope
between requests. See this link for details.

http://perl.apache.org/docs/1.0/guide/porting.html

> [Sat Dec 18 14:43:31 2004] [error] [client 10.0.0.3] (8)Exec format
> error: exec of '/var/www/localhost/perl/hello.pl' failed
> [Sat Dec 18 14:43:31 2004] [error] [client 10.0.0.3] Premature end of
> script headers: hello.pl
>
> in my logs. I read somewhere in the docs when using mod_perl that the
> #!/usr/bin/perl is no longer required, so I'm thinking maybe I'm not
> done with the apache configuration?
>
>
> What is the advantage to running mod_perl versus just running perl
> scripts out of my cgi-bin ? I suspect there is a performance gain
> from to the interpreter already existing in memory or something, but
> is there some new syntax I get to use now? Can I now include Perl
> code directly into my html?


I am relatively new to mod_perl myself and I continue to be amazed by what I
have available via mod_perl. And the performance gain really cannot be
overestimated for heavy-traffic sites, it seems.

As for putting perl into your HTML, you may find templating is what you are
interested in. There a number of options (see
http://perl.apache.org/docs/tutoria...comparison.html), most
of which do not require mod_perl. I wouldn't put that high on my list of
reasons to change from cgi to mod_perl. In fact, there are many good
reasons NOT to put perl (or really much of any logic) into your HTML.

Sean


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com