How to set PHP environment variables on Ubuntu

6,541

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:
6,541

Related videos on Youtube

I. Cantrell
Author by

I. Cantrell

I look forward to the robots taking over.

Updated on September 18, 2022

Comments

  • I. Cantrell
    I. Cantrell over 1 year

    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!

  • I. Cantrell
    I. Cantrell over 12 years
    Looks like it should be right, but <? echo $_ENV['VAR_SET_IN_ENVVARS'] ?> isn't working. :(
  • stew
    stew over 12 years
    you php script is running via mod_php? or as a cgi?
  • I. Cantrell
    I. Cantrell over 12 years
    it's running through mod_php... i'm pretty sure. it's not in a cgi-bin dir, and a2enmod php was required.
  • I. Cantrell
    I. Cantrell over 12 years
    @zoredache yes. :)
  • Vaibhav Singhal
    Vaibhav Singhal almost 4 years
    You can also check this... stackoverflow.com/questions/29079237/…