3

I have a set of environment variables, which is created with a shell script config called from my ~/.bashrc.

Having a new user www-data running a local webserver (with lighttpd), I need it to benefit from those environment variables. More specifically, the webserver runs php scripts which need them.

Therefore, I would like to move the call to config into a general file.

Reading the Ubuntu documentation related to environment variables, I tried to:

  • write export VAR="variable to /etc/profile.d/config.sh, but when running the webserver scripts, the $VAR variable is not accessible.
  • write export VAR="variable into /etc/bash.bashrc, but same issue

=> How can I share an environment variable between different unix users if I cannot make them logout (like www-data)?

Moreover, I need this environment to be loaded regularely (in case the configuration changes).

=> How can I be sure that the webserver php scripts are using the correct environment variables, without having to load the config inside every script?

terdon
  • 234,489
  • 66
  • 447
  • 667
Jav
  • 960
  • 3
  • 11
  • 23

1 Answers1

1

According to the lighttpd documentation at http://redmine.lighttpd.net/projects/1/wiki/Docs_ModSetEnv the correct way to do this is to use mod_setenv -

setenv.add-environment

Adds a value to the process environment (aka environment variables) that is passed to the external applications:

setenv.add-environment = ( 
  "TRAC_ENV" => "lighttpd",
  "RAILS_ENV" => "production" 
)
roaima
  • 107,089
  • 14
  • 139
  • 261
  • thanks, but for my *set* of environment variables (that is subject to change anyway), is there an easier alternative? – Jav Nov 24 '15 at 08:16