I'm trying to add an environment variable to use in my Rails App. Currently, our app uses several environment variables defined in /etc/environment
. They work fine. So I've added a new variable to /etc/environment
(and rebooted for the hell of it). But when I try to access the new variable, its undefined. Printing out ENV.inspect
shows all the original variables, but not my newly added one. Why oh why?
Running Apache 2 / Passenger 4 / Rails 4. Recently upgraded from Passenger 2 / Rails 3 if its significant.
Edit
Turns out the ones I thought 'work fine' don't work either (they're redefined in my Rails app). So none of the variables in /etc/environment
are loaded into the app. Not sure why I thought that system worked, but it doesn't.
Might not be good news to you, but you have to reboot the instance to see it happen (or check the other tricks at that question).
You can also use SetEnv
at your Apache config and just restarting apache itself will make your app see the new values.
ENV
Upgrading from Rails 3 - Rails 4 should not be a major concern for the ENV
variables, unless the way Rails processes them will have changed.
We use the following:
This works for us with Rails 4, Ubuntu 12.04, Passenger, Apache 2
--
The problem you may have is that your Rails application has not updated since you added the new variables.
When you run a Rails app, it essentially loads an "instance" of the application, and then keeps loading it somehow. I'm not totally sure how it works, but I do know the likes of Passenger
essentially "cache" a rails app whilst in production
This means if you're adding new Environment variables, perhaps the likes of Passenger
has made it so the Rails application has not been updated? If this is the case you may wish to use the touch tmp/restart.txt
command:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With