Environent Variables through PHP/Apache running on Linux

I'm trying to  make an environment variable  available to a PHP script.
I have exported the variable in /etc/profile, and it is available to all users including apache.  (I temporarily allowed apache shell access through /etc/passwd to see what is going on)

but when I put: "PassEnv MYVAR" into /etc/httpd/conf/httpd.conf I get the following warning:
[Wed Apr 21 10:44:09 2010] [warn] PassEnv variable MYVAR was undefined
and its unavailable.

I tried the following in PHP: echo exec ("env> /tmp/env.txt")
and the output is as follows:
TERM=xterm
PATH=/sbin:/usr/sbin:/bin:/usr/bin
_=/bin/env
PWD=/var/www/html
LANG=C
SHLVL=3


How can I get access to the variable MYVAR?
LVL 4
amroxAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

medveddCommented:
To use PassEnv you need to set up variables in shell process which starts httpd.
You can put this variables in /etc/sysconfig/httpd file, for example:

MYVAR=1

and restart httpd.

If you want to set variable in httpd.conf, you should use SetEnv directive:

SetEnv MYVAR 1

Otherwise, you can set variables for php in .htaccess file

php_value name value
0
amroxAuthor Commented:
I'm not sure I get you....

I don't want to set it anywhere else, its already set in /etc/profile.

If I was to declare it in sysconfig/httpd, then it becomes a separate variable.  I need to be able to access the GLOBAL var not a LOCAL one.

Are you saying this cannot be done?

Also, where is it getting these from:
TERM=xterm
PATH=/sbin:/usr/sbin:/bin:/usr/bin
_=/bin/env
PWD=/var/www/html
LANG=C
SHLVL=3

These are not passenv'd or declared anywhere in sysconfig/httpd or /etc/httpd/conf/* or conf.d/*

0
medveddCommented:
/etc/profile sets variables only for login shells. httpd is started from init, and init is not processing /etc/profile
Some of variables you mentioned are inherited from init, some are set in /etc/init.d/httpd script
 
0
amroxAuthor Commented:
Have solved it.
The solution was to source the /etc/profile file before...

so the PHP command would be:

echo exec (". /etc/profile; env> /tmp/env.txt")

This now gives me all the env vars including ofcourse the one that i wanted
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux

From novice to tech pro — start learning today.