简体   繁体   English

使用capistrano,passenger和apache部署rails

[英]Deploying rails with capistrano, passenger and apache

I have recently set up a VPS and am trying to deploy a rails app. 我最近设置了一个VPS,我正在尝试部署一个rails应用程序。 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. 我观看了一个截屏视频: http//railscasts.com/episodes/335-deploying-to-a-vps ,它解释了如何使用nginx设置capistrano和unicorn,还提供了apache的示例。

I followed online guide for setting up passenger and adapted the railscasts capistrano recipe. 我按照在线指南设置乘客并改编了railscasts capistrano配方。 When I run cap deploy:setup some directories are created on my server in the root of the application. 当我运行cap deploy:setup在应用程序的根目录中,在我的服务器上创建一些目录。 Then when I run cap deploy the rails app is put into the releases folder and in a directory named by timestamp. 然后当我运行cap deploy ,rails app被放入releases文件夹和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. 所以有一段时间我导航到http://dev.gregchapple.com/site/index我遇到了一些乘客错误,说某些宝石丢失了,所以我使用捆绑器将它们安装在服务器上,然后错误就消失了。 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." 现在,当我访问http://dev.gregchapple.com/site/index时,它说的是:“我们很抱歉,但出了点问题。”

The apache log contains this: apache日志包含:

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. 我的apache配置文件已被更改,以将文档根目录设置为乘客文档指定的公共目录。 I dont know what the problem is and its driving me insane! 我不知道问题是什么,它让我疯了!

Any help is greatly appreciated :) 任何帮助是极大的赞赏 :)

UPDATE UPDATE

This is what appears the production.log file: 这是出现在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>'

Update 2 更新2

database.yml 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

Your app is looking for the mysql2 adapter, so make sure in your Gemfile you have 你的应用程序正在寻找mysql2适配器,所以请确保你的Gemfile

gem 'mysql2'

and that you bundle install and that in your database.yml file you are using the mysql2 adapter. bundle install和您在database.yml文件中使用mysql2适配器。

production:
  adapter: mysql2
  ...

And don't forget to restart Passenger - touch tmp/restart.txt from the root of the Rails app. 并且不要忘记重新启动Passenger - 从Rails应用程序的根目录touch tmp/restart.txt

Congrats! 恭喜! You're almost there! 你快到了!

I had similar problem like you. 我有类似你的问题。 I changed these rows in database.yml add 我在database.yml add中更改了这些行

host: 127.0.0.1 主持人:127.0.0.1

remove 去掉

socket: /tmp/mysql.sock 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). 您必须使用capistrano更新代码中的所有内容,不要更改VPN上的代码(您只能创建tmp目录)。 You check your sql connection manualy with ssh on vpn. 你在vpn上用ssh检查你的sql连接。 For example 例如

mysql -u gregchapple -p mysql -u gregchapple -p

Your virtual host is ok? 你的虚拟主机好吗?

Your Rails app's database.yml 's production section is not configured properly. 您的Rails应用程序的database.yml的生产部分配置不正确。

  1. Configure mysql database on your server. 在服务器上配置mysql数据库。
  2. Configure production section in database.yml in your rails app and provide db username and password for production server. 在rails应用程序中配置database.yml中的生产部分,并为生产服务器提供db用户名和密码。
  3. Deploy again. 再次部署。
  4. Test. 测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM