Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Environment variables under mod_perl 2

by sgifford (Prior)
on Jun 03, 2009 at 06:25 UTC ( #767907=perlquestion: print w/ replies, xml ) Need Help??
sgifford has asked for the wisdom of the Perl Monks concerning the following question:

Hello,

I'm working on porting some code that's been running on mod_perl 1 for a very long time to mod_perl 2. Mostly things have gone smoothly, but I'm having trouble with environment variables. Sometimes my scripts go off and run other scripts, and expect to be able to set things like $ENV{PATH} for the child processes. However, for some reason under mod_perl 2, my environment variables aren't getting passed to child processes! Quite bizarre.

Here's an example:

#!/usr/bin/perl -T use strict; use warnings; print "Content-type: text/plain\n\n"; $ENV{PATH}="/usr/bin"; print "PARENT: PATH is $ENV{PATH}\n"; print " CHILD: PATH is ",`echo \$PATH`,"\n";
The proper output seems pretty obvious, right? And that's what it does when I run it from the command-line. But under mod_perl 2, instead I see:
PARENT: PATH is /usr/bin CHILD: PATH is /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbi +n:/bin:/usr/X11R6/bin

I'm using Ubuntu 8.04 and its default Perl (5.8.8), Apache (2.2.8), and mod_perl (2.0.3). My Apache configuration looks roughly like this:

<Location /cgi-perl> Options +ExecCGI PerlSendHeader On SetHandler perl-script PerlHandler ModPerl::Registry PerlOptions +SetupEnv allow from all </Location>
Any suggestions would be appreciated!

Comment on Environment variables under mod_perl 2
Select or Download Code
Re: Environment variables under mod_perl 2
by Anonymous Monk on Jun 03, 2009 at 07:01 UTC
    If you want taint, you need PerlSwitches -wT
Re: Environment variables under mod_perl 2
by Anonymous Monk on Jun 03, 2009 at 07:11 UTC
Re: Environment variables under mod_perl 2
by ysth (Canon) on Jun 03, 2009 at 07:42 UTC
    As suggested in someone else's link, use Stas's Env::C module. But make sure you aren't running a threaded mpm. You may want to use ModPerl::RegistryPrefork, which will enforce this as well as doing a chdir to the cgi's directory the way that Apache::Registry did.
Re: Environment variables under mod_perl 2
by sgifford (Prior) on Jun 03, 2009 at 18:56 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://767907]
Approved by vinoth.ree
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (13)
As of 2014-08-28 10:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (259 votes), past polls