Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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)


share|improve this question
up vote 3 down vote accepted

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

share|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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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