Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?


Edit 1 :

My first solution was :

for Apache/PHP in vhost :

SetEnv APPLICATION_ENV 'production'

for Ruby :

export APPLICATION_ENV='production'

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

share|improve this question

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'
share|improve this answer
PHP with Apache, can use this variable ? – Bastien D Jul 4 '13 at 14:17

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.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .