I have read the question/answers here but I don't understand how to set variables in /etc/environment. If I edit the file, do I need to restart my machine or simply log out my current user (or log in a new one?).
I want to set a global variable to denote that websites on my machine are in 'development' or 'testing' mode. I don't want to have to set this for every project (whether it uses PHP, Java/Tomcat, NodeJS, etc). I'm aware that (for Apache) I can set the environment variable in the following ways:
- directly from php with
putenv()
(this seems useless since I want to avoid logic that tries to figure out what server the files are on) - using .htaccess
SetEnv ENVIRONMENT 'local'
(this would require me to duplicate this file/code for every server, not ideal) - using a Virtual Host directive
SetEnv ENVIRONMENT 'local'
(if I'm using a virtual host, which in nearly all cases I am, but again requires me to copy/paste code over and over again) - in httpd-conf
SetEnv ENVIRONMENT 'local'
(this will only apply to apache, and I would like it to apply to NodeJS servers as well)
I'm not saying I can't do #4 (and apply #3 selectively to NodeJS servers). But I'm thinking that this is a good reason to use /etc/environment. As I said above, I have edited the file (after first creating it) and tried the following combinations, none of which seemed to work:
ENVIRONMENT='local'
ENVIRONMENT=local
export ENVIRONMENT='local'
export ENVIRONMENT=local
I say that none of them worked because I did not find the variable in output from:
print_r($_SERVER);
print_r($_ENV);
echo(getenv('ENVIRONMENT'));