使用capistrano,passenger和apache部署rails

时间:2012-08-06 20:38:24

标签: ruby-on-rails apache deployment capistrano passenger

我最近设置了VPS,并尝试部署rails应用程序。我观看了一个截屏视频:http://railscasts.com/episodes/335-deploying-to-a-vps,它解释了如何使用nginx设置capistrano和unicorn,还提供了apache的示例。

我按照在线指南设置乘客并调整了railscasts capistrano配方。当我运行cap deploy:setup时,在我的服务器上的应用程序根目录中创建了一些目录。然后当我运行cap deploy时,rails app被放入releases文件夹和timestamp命名的目录中。所以那部分似乎工作正常。

然后有一段时间我导航到http://dev.gregchapple.com/site/index我遇到了一些乘客错误,说某些宝石丢失了,所以我使用捆绑器将它们安装在服务器上然后错误就消失了。那是当前问题出现的时候。现在,当我去http://dev.gregchapple.com/site/index时,它只是说:“我们很抱歉,但出了点问题。”

apache日志包含:

cache: [GET /site/index] miss
cache: [GET /] miss

有谁知道问题是什么? 我的apache配置文件已被更改,以将文档根目录设置为乘客文档指定的公共目录。我不知道问题是什么,它让我疯了!

非常感谢任何帮助:)

更新

这就是production.log文件中出现的内容:

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>'

更新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

3 个答案:

答案 0 :(得分:1)

您的应用正在寻找mysql2适配器,因此请确保您的Gemfile中有

gem 'mysql2'

并且您bundle install以及database.yml文件中正在使用mysql2适配器。

production:
  adapter: mysql2
  ...

不要忘记从Rails应用程序的根目录重启Passenger - touch tmp/restart.txt

恭喜!你快到了!

答案 1 :(得分:1)

我遇到了类似你的问题。我在database.yml中更改了这些行 添加

  

主持人:127.0.0.1

除去

  

socket:/tmp/mysql.sock

然后:

cap deploy:setup
cap deploy:check
cap deploy:cold
#some updates with custom code
cap deploy:update

您必须使用capistrano更新代码中的所有内容,不要更改VPN上的代码(您只能创建tmp目录)。 你在vpn上用ssh检查你的sql连接。例如

  

mysql -u gregchapple -p

你的虚拟主机好吗?

答案 2 :(得分:0)

您的Rails应用database.yml的制作部分配置不正确。

  1. 在服务器上配置mysql数据库。
  2. 在rails应用程序中配置database.yml中的生产部分,并为生产服务器提供db用户名和密码。
  3. 再次部署。
  4. 测试。