I'm sure this is easy if you know how, but I don't.

I've got an ubuntu 10.04 server running PHP5 under apache, all defaults and stuff. The PHP needs some environment variables set. How do I do it?

Do I put them in the apache site config? Do I set them for the nobody user? (Who doesn't have a .profile)

Thanks!

link|improve this question

56% accept rate
feedback

1 Answer

The canonical place to set environment variables for apache in ubuntu is /etc/apache2/envvars. Note that apache would run as the www-data user, not the nobody user. www-data wouldn't have dotfiles in its home anyway.

Additionally, to make the variable available to php, I believe you will need to use PassEnv in the apache configuration

link|improve this answer
Looks like it should be right, but <? echo $_ENV['VAR_SET_IN_ENVVARS'] ?> isn't working. :( – Leopd Dec 13 '11 at 19:40
you php script is running via mod_php? or as a cgi? – stew Dec 13 '11 at 19:40
it's running through mod_php... i'm pretty sure. it's not in a cgi-bin dir, and a2enmod php was required. – Leopd Dec 13 '11 at 19:42
Did you restart Apache so that envars would be reloaded? – Zoredache Dec 13 '11 at 19:52
@zoredache yes. :) – Leopd Dec 13 '11 at 19:54
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.