2

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?

  • What webserver are you running? – terdon Nov 23 '15 at 16:27
  • I'm using lighttpd (thanks for the comment, I'm updating the question) – Jav Nov 23 '15 at 16:31
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" 
)
  • thanks, but for my set of environment variables (that is subject to change anyway), is there an easier alternative? – Jav Nov 24 '15 at 8:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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