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!

In reply to Environment variables under mod_perl 2 by sgifford

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.