How to add a linux environment variable for different language (PHP or RUBY)

1

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

Bastien D

Posted 2013-07-04T13:52:27.590

Reputation: 111

Answers

0

Just add the export line to your ~/.bashrc:

export APPLICATION_ENV='production'

Then, if you want to change it, run this from the terminal:

export APPLICATION_ENV='development'

terdon

Posted 2013-07-04T13:52:27.590

Reputation: 45 216

PHP with Apache, can use this variable ? – Bastien D – 2013-07-04T14:17:56.507

0

You could write the code you used in a function for both which accepts the variable name and the value.

Then just call your custom_env_variable('APPLICATION_ENV','production'); when you need it. Basically suggesting a wrapper.

Garet Claborn

Posted 2013-07-04T13:52:27.590

Reputation: 195