Re: Defining environment variables and cgi scripts
On Sat, Dec 03, 2005 at 10:15:55PM -0500, Tom Moore wrote:
> I have a cgi script I want apache to execute for me.
> The problem I'm having is I don't know how to include editional
> environmental variables that the script requires.
> How do I add a variable called PAYMENTIC_HOME to the list of environment
> variables that perl knows about when executing a script under apache?
> If I define it like:
> export $PAYMENTECH_HOME=/usr/local/paymentech from the shel before I run
> perl script.cgi everything owrks fine.
> If I run it under apache the system doesn't pass the PAYMENTECH_HOME
> variable to the script.
> Any ideas how I can get this to work?
There are several ways to do this. One way would be to use the
"PassEnv" directive in httpd.conf to tell apache to pass certain
environment variables from its own environment (i.e. that of the apache
server process) to any CGI scripts being run. Apache doesn't blindly
pass on its environment to CGI processes (despite the fact that they're
all child processes of httpd) -- IOW, it filters variables by default.
Of course, for that to work you'd also first have to set the variable
in question from wherever apache is started. Normally, that would be
/etc/init.d/apache, so you could put your definition right in there
(somewhere near the top):
Or have it source some other file which holds these settings, etc.,
which would be easier to maintain in the long run.
Another way would be to use "SetEnv" to declare env variables directly.
For easier handling, I'd put such stuff in some seperate file, and have
that be included from the main httpd.conf.
In general, this kind of functionality is provided by the apache module
"mod_env", so make sure that's loaded...
Also see http://httpd.apache.org/docs/2.0/env.html and in particular
http://httpd.apache.org/docs/2.0/mod/mod_env.html -- and if you still
have unanswered questions, don't hesitate to report back here :)