My database.yml is set up as such:
development:
adapter: mysql2
encoding: utf8
database: devel
username: root
host: localhost
port: 3306
timeout: 5000
# ... snip ...
production:
adapter: mysql2
encoding: utf8
database: prod
username: <%= ENV["DB_USER"] %>
password: <%= ENV["DB_PASSWORD"] %>
host: <%= ENV["DB_HOST"] %>
port: 3306
timeout: 5000
The issue is, though, despite setting my environmental variables, Rails is not reading these properly. When I start up my Phusion-backed Nginx server on EC2, I get this message:
Access denied for user 'root'@'localhost' (using password: NO) (Mysql2::Error)
I confirmed that Phusion is starting Rails in the production environment; I changed the usernames and hosts in the development and test configuration to unique names, and 'root'@'localhost'
always showed up as the error message. In addition, if I hard-code the username and password into the YAML file, the server starts up properly.
I suspect that I'm not setting my environmental variables correctly because MySQL keeps claiming that I'm trying to log in as 'root' without a password. I initially had them exported from the .bashrc file, but after reading this question, I realized that this was not the proper way to do it. After searching around, I happened upon this blog post, so I followed the instructions and created these three files:
/usr/local/etc/env
export RAILS_ENV=production
export DB_PASSWORD= (snip)
export DB_USER=doorbells
/usr/local/etc/ruby_wrapper
#!/bin/sh
source /usr/local/etc/env
exec /home/rooby/.rvm/wrappers/ruby-1.9.3-p362@doorbells-dev/ruby "$@"
/etc/profile.d/env.sh
#!/bin/sh
source /usr/local/etc/env
In my nginx.conf file, I use this line:
passenger_ruby /usr/local/etc/ruby_wrapper;
I've rebooted my server to no avail. Any ideas?