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

(ugh - had this all typed out, and then the power went out. second time's the charm..)

I can't seem to get mod_perl to 'activate' on my system. I have a small program (testit.html - yes, I know that it has an .html extension, but that is taken care of) That prints out all the ENV variables:
#!/usr/bin/perl -X print "Content-type: text/plain\n\n"; print "Server's environment\n"; foreach ( keys %ENV ) { print "$_\t$ENV{$_}<br>\n"; } exit;
These two variables are of note:
GATEWAY_INTERFACE CGI/1.1 MOD_PERL mod_perl/1.99_16
See how there is a mod_perl var, but the gateway is still CGI?

Here's my conf:
LoadModule perl_module modules/mod_perl.so Alias /diroftest "/var/www/html/diroftest" <Directory "/var/www/html/billy2/bvs"> Options Indexes FollowSymLinks Options +Includes DirectoryIndex index.shtml SetHandler perl-script AddHandler perl-script .html Options +ExecCGI PerlHandler ModPerl::PerlRun # PerlHandler ModPerl::Registry # PerlOptions +ParseHeaders AllowOverride None Order allow,deny Allow from all </Directory>

For the record, I get the exact same error if:
- I use ScriptAlias instead of Alias
- I use ::Registry instead of ::PerlRun

Any idea why this gateway wouldn't be flipping over to CGI-Perl/1.1? It has to be something stupid on my part..

Replies are listed 'Best First'.
Re: Getting mod_perl to actually 'activate'..
by perrin (Chancellor) on Feb 16, 2009 at 16:58 UTC
    Stop worrying. If $ENV{MOD_PERL} is defined, you are running under mod_perl, not CGI. However, I'd suggest you upgrade your mod_perl since the one you have there is buggy and about 4 years old.
      Thanks! However, if that's true, how come code that looks like this:
      #!/usr/bin/perl sub name_of_sub_1{ return 1; } sub name_of_sub_2{ return 1; } ... sub name_of_sub_100{ return 1; } ##actual code here exit;
      Still takes a long time to run every instance that the code is called from an http request? Wouldn't all those subroutines just get loaded into memory once, drastically shortening the runtime?

      (Thanks, by the way for all your help!)
        The code you're showing here will take no time at all to run under mod_perl since it will be compiled into constants on the first request. However, keep in mind that we're talking about the first request per process, so you may hit a different child process each time on your first few clicks. An easy way to tell is it to put something like this in your script:
        our $counter; $counter++; print $counter;
Re: Getting mod_perl to actually 'activate'..
by Illuminatus (Curate) on Feb 16, 2009 at 16:01 UTC
    Is this a case where you run the first script from the command line, but run the other page from a server (presumably apache) context? If so, then you are probably running into a common problem. The script that is failing is running in the context of the web server. It may not be running with the user, environment, nor pwd that you expect.
      Can you be more specific in your answer? I'm afraid I don't understand your answer enough to even look into where to go next.
        OK, you have 2 scripts in your example. The first demonstrates that your ENV is what you desire. My question was, are you running that test script from the command line? I assume you are running the latter script from within a web server. When the web server runs a script it does so from within the context of the web server. This context is usually done with the environment of the web server, using the web server' user name. This may not be what you expect.