Discussion:
SetEnv not doing what I'd hoped
(too old to reply)
Stuart McGraw
2012-06-17 20:37:13 UTC
Permalink
I am having a problem get SetEnv to work (at least
as I think it is supposed to). I have some python
cgi scripts that start with:

#!/usr/bin/env python

I cannot (for logistical reasons) change these scripts.
However, the system python in /usr/bin/ is an old version
that the scripts will not run correctly with.

I installed a new version of python in /opt/python/
and added a SetEnv option to change PATH, putting the
new python interpreter directory first:

ScriptAlias /mydir/cgi/ /home/stuart/devel/web/cgi/
Alias /mydir/ /home/stuart/devel/web/
<Directory /home/stuart/devel/web>
SetEnv PATH /opt/python/bin:/usr/bin:/bin
...other stuff...
</Directory>

I confirmed that the new python is installed ok, runs correctly
when I set my own path as above, etc.

However, when I put a cgi script that prints its environment
variables in the web directory, and view it with a browser,
it shows the PATH has not been changed (and the old interpreter
is executing it.) The config section above does and has been
working fine (except the the wrong python is executed.)

Am I doing something wrong? How can I get this to work?
I R A Darth Aggie
2012-06-19 22:36:00 UTC
Permalink
On Sun, 17 Jun 2012 14:37:13 -0600,
Post by Stuart McGraw
I am having a problem get SetEnv to work (at least
as I think it is supposed to). I have some python
#!/usr/bin/env python
I cannot (for logistical reasons) change these scripts.
However, the system python in /usr/bin/ is an old version
that the scripts will not run correctly with.
I installed a new version of python in /opt/python/
and added a SetEnv option to change PATH, putting the
ScriptAlias /mydir/cgi/ /home/stuart/devel/web/cgi/
Alias /mydir/ /home/stuart/devel/web/
<Directory /home/stuart/devel/web>
SetEnv PATH /opt/python/bin:/usr/bin:/bin
...other stuff...
</Directory>
I confirmed that the new python is installed ok, runs correctly
when I set my own path as above, etc.
However, when I put a cgi script that prints its environment
variables in the web directory, and view it with a browser,
it shows the PATH has not been changed (and the old interpreter
is executing it.) The config section above does and has been
working fine (except the the wrong python is executed.)
Am I doing something wrong? How can I get this to work?
Assuming what you want can be done, you're probably not using the
right directive. I took a gander at setenv's man page, and this jumped
out at me:

http://httpd.apache.org/docs/2.2/mod/mod_env.html#setenv

The internal environment variables set by this directive are
set after most early request processing directives are run,
such as access control and URI-to-filename mapping. If the
environment variable you're setting is meant as input into
this early phase of processing such as the RewriteRule
directive, you should instead set the environment variable
with SetEnvIf.

I would guess that PATH is set early on.

http://httpd.apache.org/docs/2.2/mod/mod_setenvif.html

If that doesn't work, you may have to modify the path that apache
knows, perhaps in its start up script. That sounds rather ugly. Why
not just upgrade your /usr/bin/python to something more modern? you
can always install older versions in /opt/ or /usr/local.
--
Consulting Minister for Consultants, DNRC
I can please only one person per day. Today is not your day. Tomorrow
isn't looking good, either.
I am BOFH. Resistance is futile. Your network will be assimilated.
Stuart McGraw
2012-06-20 14:19:31 UTC
Permalink
Post by I R A Darth Aggie
On Sun, 17 Jun 2012 14:37:13 -0600,
Post by Stuart McGraw
I am having a problem get SetEnv to work (at least
as I think it is supposed to). I have some python
#!/usr/bin/env python
I cannot (for logistical reasons) change these scripts.
However, the system python in /usr/bin/ is an old version
that the scripts will not run correctly with.
I installed a new version of python in /opt/python/
and added a SetEnv option to change PATH, putting the
ScriptAlias /mydir/cgi/ /home/stuart/devel/web/cgi/
Alias /mydir/ /home/stuart/devel/web/
<Directory /home/stuart/devel/web>
SetEnv PATH /opt/python/bin:/usr/bin:/bin
...other stuff...
</Directory>
I confirmed that the new python is installed ok, runs correctly
when I set my own path as above, etc.
However, when I put a cgi script that prints its environment
variables in the web directory, and view it with a browser,
it shows the PATH has not been changed (and the old interpreter
is executing it.) The config section above does and has been
working fine (except the the wrong python is executed.)
Am I doing something wrong? How can I get this to work?
Assuming what you want can be done, you're probably not using the
right directive. I took a gander at setenv's man page, and this jumped
http://httpd.apache.org/docs/2.2/mod/mod_env.html#setenv
The internal environment variables set by this directive are
set after most early request processing directives are run,
such as access control and URI-to-filename mapping. If the
environment variable you're setting is meant as input into
this early phase of processing such as the RewriteRule
directive, you should instead set the environment variable
with SetEnvIf.
I would guess that PATH is set early on.
http://httpd.apache.org/docs/2.2/mod/mod_setenvif.html
If that doesn't work, you may have to modify the path that apache
knows, perhaps in its start up script. That sounds rather ugly. Why
not just upgrade your /usr/bin/python to something more modern? you
can always install older versions in /opt/ or /usr/local.
Thanks for the suggestions.

I should have said in my original post that I'd tried SetEnvIf
with the same lack of effect as SetEnv.

My problem is that I am the supplier of some cgi scripts but I
do not control the server. The powers that be insist that they
aren't going to update python nor do they want to perturb (ie
run with a newer version of python) their other existing cgi
apps so starting Apache with a different PATH is not an option.

Some more googling after my original post turned up that the
ineffectiveness of SetEnv seems to be known but undocumented
in the Apache docs. (A disappointment in what I've always
thought was a model of good docs.) I gather it works in
Apache 2.3/2.4:
https://issues.apache.org/bugzilla/show_bug.cgi?id=43906

So unless someone here has some clever idea, it looks like
my only option is to modify my distribution method to change
the shebang lines in my cgi files.

Loading...