Deploying rails with capistrano, passenger and apache - ruby-on-rails

I have recently set up a VPS and am trying to deploy a rails app. I watched a screencast: http://railscasts.com/episodes/335-deploying-to-a-vps which explained how to setup capistrano and unicorn with nginx, but also gave examples for apache.
I followed online guide for setting up passenger and adapted the railscasts capistrano recipe. When I run cap deploy:setup some directories are created on my server in the root of the application. Then when I run cap deploy the rails app is put into the releases folder and in a directory named by timestamp. So that part seems to work just fine.
So then for a while when i navigated to http://dev.gregchapple.com/site/index I got some passenger errors saying that certain gems were missing, so I installed them on the server using bundler then the errors went away. Thats when the current problem arose. Now when I go to http://dev.gregchapple.com/site/index all it says is: "We're sorry, but something went wrong."
The apache log contains this:
cache: [GET /site/index] miss
cache: [GET /] miss
Does anyone know what the problem is?
My apache config file has been altered to set the document root to the public directory as specified by the passenger docs. I dont know what the problem is and its driving me insane!
Any help is greatly appreciated :)
UPDATE
This is what appears the production.log file:
Started GET "/site/index" for 109.255.221.170 at 2012-08-06 13:26:13 -0700
Mysql2::Error (Access denied for user 'root'#'localhost' (using password: NO)):
mysql2 (0.3.11) lib/mysql2/client.rb:44:in `connect'
mysql2 (0.3.11) lib/mysql2/client.rb:44:in `initialize'
activerecord (3.2.1) lib/active_record/connection_adapters/mysql2_adapter.rb:16:in `new'
activerecord (3.2.1) lib/active_record/connection_adapters/mysql2_adapter.rb:16:in `mysql2_connection'
activerecord (3.2.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:277:in `new_connection'
activerecord (3.2.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:287:in `checkout_new_connection'
activerecord (3.2.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:235:in `block (2 levels) in checkout'
activerecord (3.2.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:230:in `loop'
activerecord (3.2.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:230:in `block in checkout' /home/greg/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
activerecord (3.2.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:229:in `checkout'
activerecord (3.2.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:95:in `connection'
activerecord (3.2.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:374:in `retrieve_connection'
activerecord (3.2.1) lib/active_record/connection_adapters/abstract/connection_specification.rb:168:in `retrieve_connection'
activerecord (3.2.1) lib/active_record/connection_adapters/abstract/connection_specification.rb:142:in `connection'
activerecord (3.2.1) lib/active_record/query_cache.rb:67:in `rescue in call'
activerecord (3.2.1) lib/active_record/query_cache.rb:61:in `call'
activerecord (3.2.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:443:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
activesupport (3.2.1) lib/active_support/callbacks.rb:405:in `_run__3520547282522082875__call__1971459733125288916__callbacks'
activesupport (3.2.1) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.1) lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
activesupport (3.2.1) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.1) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
railties (3.2.1) lib/rails/rack/logger.rb:26:in `call_app'
railties (3.2.1) lib/rails/rack/logger.rb:16:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/request_id.rb:22:in `call'
rack (1.4.1) lib/rack/methodoverride.rb:21:in `call'
rack (1.4.1) lib/rack/runtime.rb:17:in `call'
activesupport (3.2.1) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.4.1) lib/rack/lock.rb:15:in `call'
rack-cache (1.2) lib/rack/cache/context.rb:136:in `forward'
rack-cache (1.2) lib/rack/cache/context.rb:245:in `fetch'
rack-cache (1.2) lib/rack/cache/context.rb:185:in `lookup'
rack-cache (1.2) lib/rack/cache/context.rb:66:in `call!'
rack-cache (1.2) lib/rack/cache/context.rb:51:in `call'
railties (3.2.1) lib/rails/engine.rb:479:in `call'
railties (3.2.1) lib/rails/application.rb:220:in `call'
railties (3.2.1) lib/rails/railtie/configurable.rb:30:in `method_missing'
passenger (3.0.15) lib/phusion_passenger/rack/request_handler.rb:96:in `process_request'
passenger (3.0.15) lib/phusion_passenger/abstract_request_handler.rb:516:in `accept_and_process_next_request'
passenger (3.0.15) lib/phusion_passenger/abstract_request_handler.rb:274:in `main_loop'
passenger (3.0.15) lib/phusion_passenger/rack/application_spawner.rb:206:in `start_request_handler'
passenger (3.0.15) lib/phusion_passenger/rack/application_spawner.rb:171:in `block in handle_spawn_application'
passenger (3.0.15) lib/phusion_passenger/utils.rb:470:in `safe_fork'
passenger (3.0.15) lib/phusion_passenger/rack/application_spawner.rb:166:in `handle_spawn_application'
passenger (3.0.15) lib/phusion_passenger/abstract_server.rb:357:in `server_main_loop'
passenger (3.0.15) lib/phusion_passenger/abstract_server.rb:206:in `start_synchronously'
passenger (3.0.15) lib/phusion_passenger/abstract_server.rb:180:in `start'
passenger (3.0.15) lib/phusion_passenger/rack/application_spawner.rb:129:in `start'
passenger (3.0.15) lib/phusion_passenger/spawn_manager.rb:253:in `block (2 levels) in spawn_rack_application'
passenger (3.0.15) lib/phusion_passenger/abstract_server_collection.rb:132:in `lookup_or_add'
passenger (3.0.15) lib/phusion_passenger/spawn_manager.rb:246:in `block in spawn_rack_application'
passenger (3.0.15) lib/phusion_passenger/abstract_server_collection.rb:82:in `block in synchronize'
<internal:prelude>:10:in `synchronize'
passenger (3.0.15) lib/phusion_passenger/abstract_server_collection.rb:79:in `synchronize'
passenger (3.0.15) lib/phusion_passenger/spawn_manager.rb:244:in `spawn_rack_application'
passenger (3.0.15) lib/phusion_passenger/spawn_manager.rb:137:in `spawn_application'
passenger (3.0.15) lib/phusion_passenger/spawn_manager.rb:275:in `handle_spawn_application'
passenger (3.0.15) lib/phusion_passenger/abstract_server.rb:357:in `server_main_loop'
passenger (3.0.15) lib/phusion_passenger/abstract_server.rb:206:in `start_synchronously'
passenger (3.0.15) helper-scripts/passenger-spawn-server:99:in `<main>'
Update 2
database.yml
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: gregchapple_development
pool: 5
host: localhost
username: root
password: *****
socket: /tmp/mysql.sock
test:
adapter: mysql2
encoding: utf8
reconnect: false
database: gregchapple_test
pool: 5
host: localhost
username: root
password: *****
socket: /tmp/mysql.sock
production:
adapter: mysql2
encoding: utf8
reconnect: false
database: gregchapple_production
pool: 5
host: localhost
username: root
password: *****
socket: /tmp/mysql.sock

I had similar problem like you. I changed these rows in database.yml
add
host: 127.0.0.1
remove
socket: /tmp/mysql.sock
Then:
cap deploy:setup
cap deploy:check
cap deploy:cold
#some updates with custom code
cap deploy:update
You must update everything in code with capistrano, DON'T CHANGE CODE ON VPN (you can create only tmp dir).
You check your sql connection manualy with ssh on vpn. For example
mysql -u gregchapple -p
Your virtual host is ok?

Your app is looking for the mysql2 adapter, so make sure in your Gemfile you have
gem 'mysql2'
and that you bundle install and that in your database.yml file you are using the mysql2 adapter.
production:
adapter: mysql2
...
And don't forget to restart Passenger - touch tmp/restart.txt from the root of the Rails app.
Congrats! You're almost there!

Your Rails app's database.yml's production section is not configured properly.
Configure mysql database on your server.
Configure production section in database.yml in your rails app and provide db username and password for production server.
Deploy again.
Test.

Related

Rails app - keeps trying to connect to localhost even though external database specified in database.yml

I have got a rails app which i am trying to get up and running, i did not build this app, however due to extenuating circumstances it falls on me to do so.
I actually don't know anything about Ruby, as it is not a programming language i use on my day to day, so please bear with me
I have managed to configure an external database to work with this app. In my database.yml, i set out the environment variables and the rake db:create/migrate/seed command has successfully created the tables on the external database which i have verified.
Just for testing purposes both the development and production environments laid out in the database.yml use the external database variables so i can rule this out as a reason why it would not be working.
Database.yml:
default: &default
adapter: mysql2
encoding: utf8
host: 127.0.0.1
port: 3306
username: root
password: root
development:
<<: *default
database: production
host: <%= ENV['DATABASE_HOST'] %>
port: 3306
username: <%= ENV['DATABASE_USERNAME'] %>
password: <%= ENV['DATABASE_PASSWORD'] %>
production:
<<: *default
database: production
host: <%= ENV['DATABASE_HOST'] %>
port: 3306
username: <%= ENV['DATABASE_USERNAME'] %>
password: <%= ENV['DATABASE_PASSWORD'] %>
As mentioned the rake command works fine, and i know it is accessing the external database because if i change the password to an incorrect one, rake gives me an error
When i run the rails server and try to access the api, i get the below error, at first it was cannot access mysql at 127.0.0.1 which i thought was odd because it was supposed to be acessing an external database, not the localhost, then i installed mysql on the same machine, and then i got password incorrect error, which obviously means that it is trying to access a local instance of mysql and not an external one. I changed the root password to match, and now i get the below when i access the api link:
(i've obfuscated the name of the api)
ActiveRecord::NoDatabaseError
Unknown database 'production'
Rails.root: /var/www/html/****-api
Application Trace | Framework Trace | Full Trace
activerecord (4.2.8) lib/active_record/connection_adapters/mysql2_adapter.rb:23:in `rescue in mysql2_connection'
activerecord (4.2.8) lib/active_record/connection_adapters/mysql2_adapter.rb:10:in `mysql2_connection'
activerecord (4.2.8) lib/active_record/connection_adapters/abstract/connection_pool.rb:438:in `new_connection'
activerecord (4.2.8) lib/active_record/connection_adapters/abstract/connection_pool.rb:448:in `checkout_new_connection'
activerecord (4.2.8) lib/active_record/connection_adapters/abstract/connection_pool.rb:422:in `acquire_connection'
activerecord (4.2.8) lib/active_record/connection_adapters/abstract/connection_pool.rb:349:in `block in checkout'
/usr/local/rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/monitor.rb:214:in `mon_synchronize'
activerecord (4.2.8) lib/active_record/connection_adapters/abstract/connection_pool.rb:348:in `checkout'
activerecord (4.2.8) lib/active_record/connection_adapters/abstract/connection_pool.rb:263:in `block in connection'
/usr/local/rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/monitor.rb:214:in `mon_synchronize'
activerecord (4.2.8) lib/active_record/connection_adapters/abstract/connection_pool.rb:262:in `connection'
activerecord (4.2.8) lib/active_record/connection_adapters/abstract/connection_pool.rb:571:in `retrieve_connection'
activerecord (4.2.8) lib/active_record/connection_handling.rb:113:in `retrieve_connection'
activerecord (4.2.8) lib/active_record/connection_handling.rb:87:in `connection'
activerecord (4.2.8) lib/active_record/migration.rb:383:in `connection'
activerecord (4.2.8) lib/active_record/migration.rb:370:in `call'
actionpack (4.2.8) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.2.8) lib/active_support/callbacks.rb:88:in `__run_callbacks__'
activesupport (4.2.8) lib/active_support/callbacks.rb:778:in `_run_call_callbacks'
activesupport (4.2.8) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (4.2.8) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.2.8) lib/action_dispatch/middleware/reloader.rb:73:in `call'
actionpack (4.2.8) lib/action_dispatch/middleware/remote_ip.rb:78:in `call'
actionpack (4.2.8) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
web-console (2.3.0) lib/web_console/middleware.rb:20:in `block in call'
web-console (2.3.0) lib/web_console/middleware.rb:18:in `catch'
web-console (2.3.0) lib/web_console/middleware.rb:18:in `call'
actionpack (4.2.8) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.2.8) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.2.8) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.2.8) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.2.8) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.2.8) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.2.8) lib/rails/rack/logger.rb:20:in `call'
actionpack (4.2.8) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.6.10) lib/rack/methodoverride.rb:22:in `call'
rack (1.6.10) lib/rack/runtime.rb:18:in `call'
activesupport (4.2.8) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
rack (1.6.10) lib/rack/lock.rb:17:in `call'
actionpack (4.2.8) lib/action_dispatch/middleware/static.rb:120:in `call'
rack (1.6.10) lib/rack/sendfile.rb:113:in `call'
rack-cors (1.0.2) lib/rack/cors.rb:97:in `call'
appoptics_apm (4.4.0) lib/appoptics_apm/inst/rack.rb:136:in `metrics_sampling_call'
appoptics_apm (4.4.0) lib/appoptics_apm/inst/rack.rb:40:in `call'
railties (4.2.8) lib/rails/engine.rb:518:in `call'
railties (4.2.8) lib/rails/application.rb:165:in `call'
rack (1.6.10) lib/rack/content_length.rb:15:in `call'
puma (3.12.0) lib/puma/configuration.rb:225:in `call'
puma (3.12.0) lib/puma/server.rb:658:in `handle_request'
puma (3.12.0) lib/puma/server.rb:472:in `process_client'
puma (3.12.0) lib/puma/server.rb:332:in `block in run'
puma (3.12.0) lib/puma/thread_pool.rb:133:in `block in spawn_thread'
Request
Parameters:
None
Toggle session dump
Toggle env dump
GATEWAY_INTERFACE: "CGI/1.2"
HTTP_ACCEPT: "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"
HTTP_ACCEPT_ENCODING: "gzip, deflate, br"
HTTP_ACCEPT_LANGUAGE: "en-GB,en-US;q=0.9,en;q=0.8"
REMOTE_ADDR: "127.0.0.1"
SERVER_NAME: "*****"
SERVER_PROTOCOL: "HTTP/1.1"
Response
Headers:
None
Any ideas? I have tried everything i can think of, i have no idea why it is not picking up connection details from database.yml

Problems with rails server

I am just getting started with ruby on rails and heroku. I am following the getting started guid on herokus website but have ran into a problem. I have logged into heroku, created an app as such rails new myapp --database=postgresql and then created a controller rails generate controller welcome index in the app/views/welcome/index.html.erb I just created a header saying hello world. When I start a local server and go to it, I get could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket "/tmp/.s.PGSQL.5432"? and the output listed bellow in the terminal I followed another tutorial just for setting up rails without heroku and created the app like this rails new blog and then did the same as created a controller like in the heroku tutorial and everything worked fine, so I assume the problem is with rails new myapp --database=postgresql How would I fix this?
PG::ConnectionBad (could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
):
activerecord (4.0.2) lib/active_record/connection_adapters/postgresql_adapter.rb:831:in `initialize'
activerecord (4.0.2) lib/active_record/connection_adapters/postgresql_adapter.rb:831:in `new'
activerecord (4.0.2) lib/active_record/connection_adapters/postgresql_adapter.rb:831:in `connect'
activerecord (4.0.2) lib/active_record/connection_adapters/postgresql_adapter.rb:548:in `initialize'
activerecord (4.0.2) lib/active_record/connection_adapters/postgresql_adapter.rb:41:in `new'
activerecord (4.0.2) lib/active_record/connection_adapters/postgresql_adapter.rb:41:in `postgresql_connection'
activerecord (4.0.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:440:in `new_connection'
activerecord (4.0.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:450:in `checkout_new_connection'
activerecord (4.0.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:421:in `acquire_connection'
activerecord (4.0.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:356:in `block in checkout'
/Users/mattmoss/.rbenv/versions/2.1.0/lib/ruby/2.1.0/monitor.rb:211:in `mon_synchronize'
activerecord (4.0.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:355:in `checkout'
activerecord (4.0.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:265:in `block in connection'
/Users/mattmoss/.rbenv/versions/2.1.0/lib/ruby/2.1.0/monitor.rb:211:in `mon_synchronize'
activerecord (4.0.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:264:in `connection'
activerecord (4.0.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:546:in `retrieve_connection'
activerecord (4.0.2) lib/active_record/connection_handling.rb:79:in `retrieve_connection'
activerecord (4.0.2) lib/active_record/connection_handling.rb:53:in `connection'
activerecord (4.0.2) lib/active_record/query_cache.rb:51:in `restore_query_cache_settings'
activerecord (4.0.2) lib/active_record/query_cache.rb:43:in `rescue in call'
activerecord (4.0.2) lib/active_record/query_cache.rb:32:in `call'
activerecord (4.0.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:626:in `call'
activerecord (4.0.2) lib/active_record/migration.rb:369:in `call'
actionpack (4.0.2) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.0.2) lib/active_support/callbacks.rb:373:in `_run__4242016335734095215__call__callbacks'
activesupport (4.0.2) lib/active_support/callbacks.rb:80:in `run_callbacks'
actionpack (4.0.2) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.0.2) lib/action_dispatch/middleware/reloader.rb:64:in `call'
actionpack (4.0.2) lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
actionpack (4.0.2) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
actionpack (4.0.2) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.0.2) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.0.2) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.0.2) lib/active_support/tagged_logging.rb:67:in `block in tagged'
activesupport (4.0.2) lib/active_support/tagged_logging.rb:25:in `tagged'
activesupport (4.0.2) lib/active_support/tagged_logging.rb:67:in `tagged'
railties (4.0.2) lib/rails/rack/logger.rb:20:in `call'
actionpack (4.0.2) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
rack (1.5.2) lib/rack/runtime.rb:17:in `call'
activesupport (4.0.2) lib/active_support/cache/strategy/local_cache.rb:83:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
actionpack (4.0.2) lib/action_dispatch/middleware/static.rb:64:in `call'
rack (1.5.2) lib/rack/sendfile.rb:112:in `call'
railties (4.0.2) lib/rails/engine.rb:511:in `call'
railties (4.0.2) lib/rails/application.rb:97:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
rack (1.5.2) lib/rack/content_length.rb:14:in `call'
rack (1.5.2) lib/rack/handler/webrick.rb:60:in `service'
/Users/mattmoss/.rbenv/versions/2.1.0/lib/ruby/2.1.0/webrick/httpserver.rb:138:in `service'
/Users/mattmoss/.rbenv/versions/2.1.0/lib/ruby/2.1.0/webrick/httpserver.rb:94:in `run'
/Users/mattmoss/.rbenv/versions/2.1.0/lib/ruby/2.1.0/webrick/server.rb:295:in `block in start_thread'
Rendered /Users/mattmoss/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.0.2/lib/action_dispatch/middleware/templates/rescues/_source.erb (0.5ms)
Rendered /Users/mattmoss/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.0.2/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.0ms)
Rendered /Users/mattmoss/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.0.2/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (1.0ms)
Rendered /Users/mattmoss/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.0.2/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (18.2ms)
Here is my database.yml
# PostgreSQL. Versions 8.2 and up are supported.
#
# Install the pg driver:
# gem install pg
# On OS X with Homebrew:
# gem install pg -- --with-pg-config=/usr/local/bin/pg_config
# On OS X with MacPorts:
# gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config
# On Windows:
# gem install pg
# Choose the win32 build.
# Install PostgreSQL and put its /bin directory on your path.
#
# Configure Using Gemfile
# gem 'pg'
#
development:
adapter: postgresql
encoding: unicode
database: myapp_development
pool: 5
password:
# Connect on a TCP socket. Omitted by default since the client uses a
# domain socket that doesn't need configuration. Windows does not have
# domain sockets, so uncomment these lines.
#host: localhost
# The TCP port the server listens on. Defaults to 5432.
# If your server runs on a different port number, change accordingly.
#port: 5432
# Schema search path. The server defaults to $user,public
#schema_search_path: myapp,sharedapp,public
# Minimum log levels, in increasing order:
# debug5, debug4, debug3, debug2, debug1,
# log, notice, warning, error, fatal, and panic
# Defaults to warning.
#min_messages: notice
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
adapter: postgresql
encoding: unicode
database: myapp_test
pool: 5
password:
production:
adapter: postgresql
encoding: unicode
database: myapp_production
pool: 5
password:
development:
host: localhost
test:
host: localhost
On most *nix servers "localhost" is handled through a Unix style socket. If you use 127.0.0.1 instead it will use TCP/IP. Try that or make sure your client and server are using the same socket address and that it is actually a usable *nix socket.
There is a configuration parameter in database.yml that lets you set the socket address, be certain that you have access to the directory as well.
In your config/database.yml, try adding
host: localhost
in each of your development and testing environment or more specifically looking at your existing config/database.yml shown above:
development:
adapter: postgresql
encoding: unicode
database: myapp_development
pool: 5
password:
host: localhost
test:
adapter: postgresql
encoding: unicode
database: myapp_test
pool: 5
password:
host: localhost
Hope this helps
I hear Heroku has made some changes to the db connection behaviour. For rails version >= 4.1 it does not overwrite your config/database.yml - it merges with it. First you need to visit https://postgres.heroku.com/databases and click on your database. You should look that parameter in the pic below
Use that variable for your production parameter like so
production:
adapter: postgresql
url: <%= ENV['HEROKU_POSTGRESQL_BLACK_URL'] %>
This is what worked for me after trying different things. I hope this helps someone.

Error while running the ruby server says connection not established

I am using rails 3.2.9 and database of postgres.
I have edited database.yml file in the following way and also gem pg was also installed..
When I run bundle command it shows pg gem in that list. But if I run the rails server command it shows the active connection not established.
development:
adapter: postgresql
database: db_pchamara/development.postgresql
pool: 5
username: database username
password: password
host: database ip address
test:
adapter: postgresql
database: database name/test.postgresql
pool: 5
username:database username
password: password
production:
adapter: postgresql
database: database name/production.postgresql
pool: 5
username: database username
password: password
But when I run command rails server it shows as follows:
[root#vdimc04 my_app]# rails server
=> Booting WEBrick
=> Rails 3.2.9 application starting in development on http
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2012-12-06 12:49:35] INFO WEBrick 1.3.1
[2012-12-06 12:49:35] INFO ruby 1.9.3 (2012-11-10) [i686-linux]
[2012-12-06 12:49:35] INFO WEBrick::HTTPServer#start: pid=7536 port=3000
Started GET "/assets/rails.png" for 127.0.0.1 at 2012-12-06 12:49:53 +0530
ActiveRecord::ConnectionNotEstablished (ActiveRecord::ConnectionNotEstablished):
activerecord (3.2.9) lib/active_record/connection_adapters/abstract/connection_pool.rb:410:in `retrieve_connection'
activerecord (3.2.9) lib/active_record/connection_adapters/abstract/connection_specification.rb:171:in `retrieve_connection'
activerecord (3.2.9) lib/active_record/connection_adapters/abstract/connection_specification.rb:145:in `connection'
activerecord (3.2.9) lib/active_record/query_cache.rb:67:in `rescue in call'
activerecord (3.2.9) lib/active_record/query_cache.rb:61:in `call'
activerecord (3.2.9) lib/active_record/connection_adapters/abstract/connection_pool.rb:479:in `call'
actionpack (3.2.9) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
activesupport (3.2.9) lib/active_support/callbacks.rb:405:in `_run__626989987__call__446659449__callbacks'
activesupport (3.2.9) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.9) lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
activesupport (3.2.9) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.9) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (3.2.9) lib/action_dispatch/middleware/reloader.rb:65:in `call'
actionpack (3.2.9) lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
actionpack (3.2.9) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
actionpack (3.2.9) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
railties (3.2.9) lib/rails/rack/logger.rb:32:in `call_app'
railties (3.2.9) lib/rails/rack/logger.rb:16:in `block in call'
activesupport (3.2.9) lib/active_support/tagged_logging.rb:22:in `tagged'
railties (3.2.9) lib/rails/rack/logger.rb:16:in `call'
actionpack (3.2.9) lib/action_dispatch/middleware/request_id.rb:22:in `call'
rack (1.4.1) lib/rack/methodoverride.rb:21:in `call'
rack (1.4.1) lib/rack/runtime.rb:17:in `call'
activesupport (3.2.9) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.4.1) lib/rack/lock.rb:15:in `call'
actionpack (3.2.9) lib/action_dispatch/middleware/static.rb:62:in `call'
railties (3.2.9) lib/rails/engine.rb:479:in `call'
railties (3.2.9) lib/rails/application.rb:223:in `call'
rack (1.4.1) lib/rack/content_length.rb:14:in `call'
railties (3.2.9) lib/rails/rack/log_tailer.rb:17:in `call'
rack (1.4.1) lib/rack/handler/webrick.rb:59:in `service'
/usr/local/rvm/rubies/ruby-1.9.3-p327/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service'
/usr/local/rvm/rubies/ruby-1.9.3-p327/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run'
/usr/local/rvm/rubies/ruby-1.9.3-p327/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'
Rendered /usr/local/rvm/gems/ruby-1.9.3-p327/gems/actionpack-3.2.9/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.3ms)
Rendered /usr/local/rvm/gems/ruby-1.9.3-p327/gems/actionpack-3.2.9/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (3.0ms)
Rendered /usr/local/rvm/gems/ruby-1.9.3-p327/gems/actionpack-3.2.9/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (29.4ms)
Please help me to solve this problem.
The problem is in the configuration of the file:
development:
adapter: postgresql
database: db_pchamara/development.postgresql
pool: 5
username: database username
password: password
host: database ip address
change it to:
development:
adapter: postgresql
database: name_of_database
pool: 5
username: db_user
password: db_pass
host: db_host
most of the time db_host is just localhost
also, make sure you can connect with psql before you actually try to connect with rails.
if the db doesn't exist, you have to create the db with
rake db:create
cheers ;)

Rails routing error. Application doesn't run

Heyy guys, please help me. I am from 4 days on dreamhost setting up rails. Finally rails has started working but application is not running. I have just deployed a demo app with only one model Products and the page doesn't opens, it says page doesn't exist. There is written routing error in production log file. I am novice in Rails so could'nt figure out what is going wrong. You can try yourself running app http://meropati.com/products and see source code of this app with log files on my git repository *https://github.com/getaasciesh/TestingRailsOnDreamHost*
I will be so thankful to get it's solution.
Started GET "/products" for 208.113.229.116 at 2012-07-26 16:05:55 -0700
ActionController::RoutingError (No route matches [GET] "/products"):
actionpack (3.2.6) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
actionpack (3.2.6) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
railties (3.2.6) lib/rails/rack/logger.rb:26:in `call_app'
railties (3.2.6) lib/rails/rack/logger.rb:16:in `call'
actionpack (3.2.6) lib/action_dispatch/middleware/request_id.rb:22:in `call'
rack (1.4.1) lib/rack/methodoverride.rb:21:in `call'
rack (1.4.1) lib/rack/runtime.rb:17:in `call'
activesupport (3.2.6) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.4.1) lib/rack/lock.rb:15:in `call'
rack-cache (1.2) lib/rack/cache/context.rb:136:in `forward'
rack-cache (1.2) lib/rack/cache/context.rb:245:in `fetch'
rack-cache (1.2) lib/rack/cache/context.rb:185:in `lookup'
rack-cache (1.2) lib/rack/cache/context.rb:66:in `call!'
rack-cache (1.2) lib/rack/cache/context.rb:51:in `call'
railties (3.2.6) lib/rails/engine.rb:479:in `call'
railties (3.2.6) lib/rails/application.rb:220:in `call'
railties (3.2.6) lib/rails/railtie/configurable.rb:30:in `method_missing'
/home/getaasciesh3/.passenger/standalone/3.0.14-x86_64-ruby1.9.3-linux-gcc4.4.5-1002/support/lib/phusion_passenger/rack/request_handler.rb:96:in `process_request'
/home/getaasciesh3/.passenger/standalone/3.0.14-x86_64-ruby1.9.3-linux-gcc4.4.5-1002/support/lib/phusion_passenger/abstract_request_handler.rb:516:in `accept_and_process_next_request'
/home/getaasciesh3/.passenger/standalone/3.0.14-x86_64-ruby1.9.3-linux-gcc4.4.5-1002/support/lib/phusion_passenger/abstract_request_handler.rb:274:in `main_loop'
/home/getaasciesh3/.passenger/standalone/3.0.14-x86_64-ruby1.9.3-linux-gcc4.4.5-1002/support/lib/phusion_passenger/rack/application_spawner.rb:206:in `start_request_handler'
/home/getaasciesh3/.passenger/standalone/3.0.14-x86_64-ruby1.9.3-linux-gcc4.4.5-1002/support/lib/phusion_passenger/rack/application_spawner.rb:171:in `block in handle_spawn_application'
/home/getaasciesh3/.passenger/standalone/3.0.14-x86_64-ruby1.9.3-linux-gcc4.4.5-1002/support/lib/phusion_passenger/utils.rb:470:in `safe_fork'
/home/getaasciesh3/.passenger/standalone/3.0.14-x86_64-ruby1.9.3-linux-gcc4.4.5-1002/support/lib/phusion_passenger/rack/application_spawner.rb:166:in `handle_spawn_application'
/home/getaasciesh3/.passenger/standalone/3.0.14-x86_64-ruby1.9.3-linux-gcc4.4.5-1002/support/lib/phusion_passenger/abstract_server.rb:357:in `server_main_loop'
/home/getaasciesh3/.passenger/standalone/3.0.14-x86_64-ruby1.9.3-linux-gcc4.4.5-1002/support/lib/phusion_passenger/abstract_server.rb:206:in `start_synchronously'
/home/getaasciesh3/.passenger/standalone/3.0.14-x86_64-ruby1.9.3-linux-gcc4.4.5-1002/support/lib/phusion_passenger/abstract_server.rb:180:in `start'
/home/getaasciesh3/.passenger/standalone/3.0.14-x86_64-ruby1.9.3-linux-gcc4.4.5-1002/support/lib/phusion_passenger/rack/application_spawner.rb:129:in `start'
/home/getaasciesh3/.passenger/standalone/3.0.14-x86_64-ruby1.9.3-linux-gcc4.4.5-1002/support/lib/phusion_passenger/spawn_manager.rb:253:in `block (2 levels) in spawn_rack_application'
/home/getaasciesh3/.passenger/standalone/3.0.14-x86_64-ruby1.9.3-linux-gcc4.4.5-1002/support/lib/phusion_passenger/abstract_server_collection.rb:132:in `lookup_or_add'
/home/getaasciesh3/.passenger/standalone/3.0.14-x86_64-ruby1.9.3-linux-gcc4.4.5-1002/support/lib/phusion_passenger/spawn_manager.rb:246:in `block in spawn_rack_application'
/home/getaasciesh3/.passenger/standalone/3.0.14-x86_64-ruby1.9.3-linux-gcc4.4.5-1002/support/lib/phusion_passenger/abstract_server_collection.rb:82:in `block in synchronize'
<internal:prelude>:10:in `synchronize'
/home/getaasciesh3/.passenger/standalone/3.0.14-x86_64-ruby1.9.3-linux-gcc4.4.5-1002/support/lib/phusion_passenger/abstract_server_collection.rb:79:in `synchronize'
/home/getaasciesh3/.passenger/standalone/3.0.14-x86_64-ruby1.9.3-linux-gcc4.4.5-1002/support/lib/phusion_passenger/spawn_manager.rb:244:in `spawn_rack_application'
/home/getaasciesh3/.passenger/standalone/3.0.14-x86_64-ruby1.9.3-linux-gcc4.4.5-1002/support/lib/phusion_passenger/spawn_manager.rb:137:in `spawn_application'
/home/getaasciesh3/.passenger/standalone/3.0.14-x86_64-ruby1.9.3-linux-gcc4.4.5-1002/support/lib/phusion_passenger/spawn_manager.rb:275:in `handle_spawn_application'
/home/getaasciesh3/.passenger/standalone/3.0.14-x86_64-ruby1.9.3-linux-gcc4.4.5-1002/support/lib/phusion_passenger/abstract_server.rb:357:in `server_main_loop'
/home/getaasciesh3/.passenger/standalone/3.0.14-x86_64-ruby1.9.3-linux-gcc4.4.5-1002/support/lib/phusion_passenger/abstract_server.rb:206:in `start_synchronously'
/home/getaasciesh3/.passenger/standalone/3.0.14-x86_64-ruby1.9.3-linux-gcc4.4.5-1002/support/helper-scripts/passenger-spawn-server:99:in `<main>'
This might not matter, but you've got:
gem 'sqlite3'
group :development, :test do
gem 'sqlite3'
end
...
gem 'mysql2'
Try removing the first reference to sqlite3 as you don't want it in production.
As I said, it might not make any difference to this particular issue, but it will save you from trouble later on
Update
The dreamhost wiki advise against using passenger and rvm, as they don't play too nicely together. Read the section titled "Troubleshooting". They recommend switching to the system installation of ruby.
If you are going to try that, you will probably need to remove the reference to rvm from environment.rb
Good luck

Rails using mysql2 instead of sqlite3

I have the following configuration:
linux ubuntu 11.04
rails 3.0.9
ruby 1.9.2p290
mysql2 (0.2.7)
I have created first my project using "rails new"
then I have modified the Gemfile to use mysql2 version 0.2.7 (I have read that later versions are working with rails 3.1 only)
Then I changed the file database.yml to use mysql2 instead of sqlite3
But now I'm getting error ActiveRecord::ConnectionNotEstablished when I try to connect to a Controller. Here are the full logs:
activerecord (3.0.9) lib/active_record/connection_adapters/abstract/connection_pool.rb:317:in `retrieve_connection'
activerecord (3.0.9) lib/active_record/connection_adapters/abstract/connection_specification.rb:97:in `retrieve_connection'
activerecord (3.0.9) lib/active_record/connection_adapters/abstract/connection_specification.rb:89:in `connection'
activerecord (3.0.9) lib/active_record/query_cache.rb:12:in `cache'
activerecord (3.0.9) lib/active_record/query_cache.rb:31:in `call'
activerecord (3.0.9) lib/active_record/connection_adapters/abstract/connection_pool.rb:354:in `call'
actionpack (3.0.9) lib/action_dispatch/middleware/callbacks.rb:46:in `call'
activesupport (3.0.9) lib/active_support/callbacks.rb:416:in `_run_call_callbacks'
actionpack (3.0.9) lib/action_dispatch/middleware/callbacks.rb:44:in `call'
rack (1.2.3) lib/rack/sendfile.rb:107:in `call'
actionpack (3.0.9) lib/action_dispatch/middleware/remote_ip.rb:48:in `call'
actionpack (3.0.9) lib/action_dispatch/middleware/show_exceptions.rb:47:in `call'
railties (3.0.9) lib/rails/rack/logger.rb:13:in `call'
rack (1.2.3) lib/rack/runtime.rb:17:in `call'
activesupport (3.0.9) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.2.3) lib/rack/lock.rb:11:in `call'
rack (1.2.3) lib/rack/lock.rb:11:in `synchronize'
rack (1.2.3) lib/rack/lock.rb:11:in `call'
actionpack (3.0.9) lib/action_dispatch/middleware/static.rb:30:in `call'
railties (3.0.9) lib/rails/application.rb:168:in `call'
railties (3.0.9) lib/rails/application.rb:77:in `send'
railties (3.0.9) lib/rails/application.rb:77:in `method_missing'
railties (3.0.9) lib/rails/rack/log_tailer.rb:14:in `call'
rack (1.2.3) lib/rack/content_length.rb:13:in `call'
rack (1.2.3) lib/rack/handler/webrick.rb:52:in `service'
/usr/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'
/usr/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
/usr/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'
/usr/lib/ruby/1.8/webrick/server.rb:162:in `start'
/usr/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'
/usr/lib/ruby/1.8/webrick/server.rb:95:in `start'
/usr/lib/ruby/1.8/webrick/server.rb:92:in `each'
/usr/lib/ruby/1.8/webrick/server.rb:92:in `start'
/usr/lib/ruby/1.8/webrick/server.rb:23:in `start'
/usr/lib/ruby/1.8/webrick/server.rb:82:in `start'
rack (1.2.3) lib/rack/handler/webrick.rb:13:in `run'
rack (1.2.3) lib/rack/server.rb:217:in `start'
railties (3.0.9) lib/rails/commands/server.rb:65:in `start'
railties (3.0.9) lib/rails/commands.rb:30
railties (3.0.9) lib/rails/commands.rb:27:in `tap'
railties (3.0.9) lib/rails/commands.rb:27
script/rails:6:in `require'
script/rails:6
PS: I tried almost all solutions provided in this website, but I still have the same issue.
I ended by recreating a new project with the command
rails new -d mysql
And now the pages are retrieved without any problem!
I tried to compare the automatic database.yml file and the manual one, the only diffrence I have noticed was on the user used for mysql database. in the new one the username: root is used.
I came back to the old project and I changed to username/password with root ones I now it is working!!!
I would guess that your database.yml file is incorrect. It should look something like this:
development:
adapter: mysql2
host: localhost
username: root
password: xxxx
database: xxxx
If that doesn't work, try changing localhost to 127.0.0.1

Resources