I would like to add a linux environment variable for my differents applications written in PHP and Ruby.
Its goal is to differntiate between 'production' and 'development' linux environment.
How to have an linux environment variable (ex : APPLICATION_ENV='production') that can be accessed with PHP and Ruby?
thanks
Edit 1 :
My first solution was :
for Apache/PHP in vhost :
SetEnv APPLICATION_ENV 'production'
for Ruby :
export APPLICATION_ENV='production'
puts ENV['APPLICATION_ENV']
However, this is two places to the same value... There are no solution to merge it in one place ? par exemple to use /etc/environment
Edit :
The answer of my question is detailed here : Inserting Variable Headers in Apache
A simple solution to have a central location for your variable would be to put it in /etc/environment
and include it in /etc/init.d/httpd
.
$ vim /etc/environment
APPLICATION_ENV=production
$ vim /etc/init.d/httpd
if [ -f /etc/environment ]; then
. /etc/environment
fi
Then restart apache with /etc/init.d/httpd restart
and it should be OK.
If you are using ubuntu 16.04 or similar, replace /etc/init.d/httpd
with /etc/init.d/apache2
If you don't want to include environment file to apache, you can directly put your code in /etc/apache2/envvars
for example at the end of the file:
export HELLO='dear'