Environment variable problem in mod_perl 2
am 03.06.2009 08:58:56 von Scott Gifford
[ also posted on PerlMonks ]
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:/sbin:/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:
Options +ExecCGI
PerlSendHeader On
SetHandler perl-script
PerlHandler ModPerl::Registry
PerlOptions +SetupEnv
allow from all
Any suggestions would be appreciated!
----Scott.
Re: Environment variable problem in mod_perl 2
am 03.06.2009 20:50:27 von Scott Gifford
Paul Silevitch writes:
> Scott,
>
> I had a similar problem and I used Env::C to get around it. Definitely read
> the perldoc to see the gotchas with this module.
>
> Let me know if it works for you,
Yeah, Env::C was the solution, thanks!
It would be very nice to make this clearer in the docs, especially the
migration guide on the Web site. Mentioning clearly that %ENV is no
longer tied the to the real environment, that this affects child
processes (not just C code), and that Env::C offers a solution would
have saved me several hours. I would be happy to provide some
suggested text for:
http://perl.apache.org/docs/2.0/user/porting/compat.html#Iss ues_with_Environment_Variables
if it would be helpful.
----Scott.
> On Wed, Jun 3, 2009 at 2:58 AM, Scott Gifford
> wrote:
>
> [ also posted on PerlMonks ]
>
> 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.
[...]
Re: Environment variable problem in mod_perl 2
am 03.06.2009 21:41:24 von gozer
This is an OpenPGP/MIME signed message (RFC 2440 and 3156)
--------------enig3AB17D8DF8D4BD7BD8834983
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
On 03/06/09 02:58 , Scott Gifford wrote:
> [ also posted on PerlMonks ]
>=20
> 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.
Have you tried using $r->subprocess_env ?
http://perl.apache.org/docs/2.0/api/Apache2/RequestRec.html# C_subprocess_=
env_
--=20
Philippe M. Chiasson GPG: F9BFE0C2480E7680 1AE53631CB32A107 88C3A5A5
http://gozer.ectoplasm.org/ m/gozer\@(apache|cpan|ectoplasm)\.org/
--------------enig3AB17D8DF8D4BD7BD8834983
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: OpenPGP digital signature
Content-Disposition: attachment; filename="signature.asc"
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (Darwin)
iD8DBQFKJtHqyzKhB4jDpaURAvjAAJ9/N5HcTcN4dVunbmvPvgiYPeGx9QCe PWRj
svrp5mQIKf2cdVQNJWJZIhU=
=6wML
-----END PGP SIGNATURE-----
--------------enig3AB17D8DF8D4BD7BD8834983--