我尝试在我的 VPS 上部署我的第一个 Rails 3.x 应用程序,但并没有真正成功。在我的 VPS 上,我使用 Apache 和 Passenger,但是当我启动应用程序时,我收到如下错误:
/var/www/my_domain_name/sample_app/config/initializers/wrap_parameters.rb:8: syntax error, unexpected ':', expecting kEND wrap_parameters format: [:json] ^
带有回溯:
0 /usr/lib64/ruby/gems/1.8/gems/activesupport-3.2.6/lib/active_support/dependencies.rb 245 in `load'
1 /usr/lib64/ruby/gems/1.8/gems/activesupport-3.2.6/lib/active_support/dependencies.rb 245 in `load'
2 /usr/lib64/ruby/gems/1.8/gems/activesupport-3.2.6/lib/active_support/dependencies.rb 236 in `load_dependency'
3 /usr/lib64/ruby/gems/1.8/gems/activesupport-3.2.6/lib/active_support/dependencies.rb 245 in `load'
4 /usr/lib64/ruby/gems/1.8/gems/railties-3.2.6/lib/rails/engine.rb 588
5 /usr/lib64/ruby/gems/1.8/gems/railties-3.2.6/lib/rails/engine.rb 587 in `each'
6 /usr/lib64/ruby/gems/1.8/gems/railties-3.2.6/lib/rails/engine.rb 587
7 /usr/lib64/ruby/gems/1.8/gems/railties-3.2.6/lib/rails/initializable.rb 30 in `instance_exec'
8 /usr/lib64/ruby/gems/1.8/gems/railties-3.2.6/lib/rails/initializable.rb 30 in `run'
9 /usr/lib64/ruby/gems/1.8/gems/railties-3.2.6/lib/rails/initializable.rb 55 in `run_initializers'
10 /usr/lib64/ruby/gems/1.8/gems/railties-3.2.6/lib/rails/initializable.rb 54 in `each'
11 /usr/lib64/ruby/gems/1.8/gems/railties-3.2.6/lib/rails/initializable.rb 54 in `run_initializers'
12 /usr/lib64/ruby/gems/1.8/gems/railties-3.2.6/lib/rails/application.rb 136 in `initialize!'
13 /usr/lib64/ruby/gems/1.8/gems/railties-3.2.6/lib/rails/railtie/configurable.rb 30 in `send'
14 /usr/lib64/ruby/gems/1.8/gems/railties-3.2.6/lib/rails/railtie/configurable.rb 30 in `method_missing'
15 /var/www/slovnyky.com/sample_app/config/environment.rb 5
16 config.ru 3 in `require'
17 config.ru 3
18 /usr/lib64/ruby/gems/1.8/gems/rack-1.4.1/lib/rack/builder.rb 51 in `instance_eval'
19 /usr/lib64/ruby/gems/1.8/gems/rack-1.4.1/lib/rack/builder.rb 51 in `initialize'
20 config.ru 1 in `new'
21 config.ru 1
我发现问题可能出在错误的 Ruby 版本中,因为 1.8.7 无法正确识别某些哈希语法。但这很奇怪,因为它不应该使用预装的 Ruby 1.8.7,而是 1.9.3。在我的 CentOS 6.2 上,我安装了 RVM 和 Ruby 1.9.3,所以我有这个:
ruby -v
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]
rvm list
rvm rubies
=* ruby-1.9.3-p194 [ x86_64 ]
# => - current
# =* - current && default
# * - default
所以很奇怪我得到:
sudo ruby -v
ruby 1.8.7 (2011-06-30 patchlevel 352) [x86_64-linux]
这就是为什么我认为出于某种原因,Passenger 选择了错误的 Ruby 版本。当我尝试像这样启动服务器时:
rails server
它可以工作,我可以通过 MY_IP:3000 访问我的应用程序而没有任何问题。
所以问题是:如何让Passenger 加载所需的Ruby 版本,而不是预装的?
这是重启后 Apache error_log 的尾部:
[Thu Jul 26 20:29:10 2012] [notice] caught SIGTERM, shutting down
[Thu Jul 26 20:29:11 2012] [notice] suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
[Thu Jul 26 20:29:11 2012] [notice] Digest: generating secret for digest authentication ...
[Thu Jul 26 20:29:11 2012] [notice] Digest: done
[Thu Jul 26 20:29:11 2012] [notice] Apache/2.2.15 (Unix) DAV/2 Phusion_Passenger/3.0.12 PHP/5.3.3 configured -- resuming normal operations