Rails 4.2 not reading Environment Variables for Database.yml
Asked Answered
C

1

0

My database.yml file does not seem to be picking up the environment variable correctly. When I put the password in directly, there are no issues, so I know it's not a password problem. I've also restarted the server.

Also, when I launch IRB on the server and type in ENV["DB_PASSWORD" it is returned:

    2.2.0 :001 > ENV["DB_PASSWORD"]
 => "tej-wir-alt-od-yirf-aj-yam-yis-ed-an-buc"

database.yml

production:
  database: myapp
  username: root
  password: <%= ENV["DB_PASSWORD"] %>
  host: localhost
  adapter: mysql2
  port: 3306
  pool: 15
  timeout: 5000

.bashrc

export MYSQL_DB=tej-wir-alt-od-yirf-aj-yam-yis-ed-an-buc
Crimea answered 30/1, 2015 at 6:39 Comment(2)
How is your app being served (passenger, unicorn etc) ? Depending on how that is setup, .bashrc might not be usedSeward
I'm using passenger - .bashrc seems to be working as I also have ENV variables for my secret_key_baseCrimea
B
4

You can set variable in .profile because it will load every time while you will reboot server.

You can add with following step:

open sudo nano ~/.profile

Then add variable

export DB_PASSWORD=tej-wir-alt-od-yirf-aj-yam-yis-ed-an-buc

Then reload profile with

. ~/.profile

And it will be work.

Baylor answered 30/1, 2015 at 7:34 Comment(2)
Thanks! Moving the following from .bashrc to .prorfile worked for me (Rails 4.2, deploying to Apache on Digital Ocean) export RAILS_DATABASE_PASSWORD='mypassword' export SECRET_KEY_BASE=secretkeyEspalier
Worked with passenger gem.Masteratarms

© 2022 - 2024 — McMap. All rights reserved.