Apache-2.2

Apache 2、Passenger 3 和 RVM 設置

  • December 28, 2011

我想用 Apache2 + Passenger3 + RVM 設置一個 RoR 伺服器,這些是我的配置

# Passenger Apache Integartion
LoadModule passenger_module /usr/local/rvm/gems/ruby-1.8.7-p352@global/gems/passenger-3.0.11/ext/apache2/mod_passenger.so
PassengerRoot /usr/local/rvm/gems/ruby-1.8.7-p352@global/gems/passenger-3.0.11
PassengerRuby /usr/local/rvm/wrappers/ruby-1.8.7-p352@global/ruby

這是我的.rvmrc

if [[ -s "/usr/local/rvm/gems/ruby-1.8.7-p352@myapp" ]] ; then
 . "/usr/local/rvm/gems/ruby-1.8.7-p352@myapp"
else
 rvm --create use  "1.8.7@myapp"
fi

myappgemset 已創建並包含所有必需的 gem,所以現在在environment.rb文件中我載入了一個 gem 文件 requirerequire 'postmark-rails'並且它顯示錯誤no such file to load -- postmark-rails (MissingSourceFile)意味著它沒有載入正確的 gemset。如何弄清楚?

.rvmrc文件無法正常工作。所以我搜尋並找到了創建.rvmrc文件的正確方法。

在目錄 home 中使用了這個命令rvm 1.8.7@myapp --rvmrc --create

這將創建正確的.rvmrc文件。然後將此程式碼放入config/setup_load_paths.rbRails 2 應用程序

if ENV['MY_RUBY_HOME'] && ENV['MY_RUBY_HOME'].include?('rvm')
 begin
   rvm_path     = File.dirname(File.dirname(ENV['MY_RUBY_HOME']))
   rvm_lib_path = File.join(rvm_path, 'lib')
   $LOAD_PATH.unshift rvm_lib_path
   require 'rvm'
   RVM.use_from_path! File.dirname(File.dirname(__FILE__))
 rescue LoadError
   # RVM is unavailable at this point.
   raise "RVM ruby lib is currently unavailable."
 end
end

對於 Rails 3

if ENV['MY_RUBY_HOME'] && ENV['MY_RUBY_HOME'].include?('rvm')
 begin
   rvm_path     = File.dirname(File.dirname(ENV['MY_RUBY_HOME']))
   rvm_lib_path = File.join(rvm_path, 'lib')
   $LOAD_PATH.unshift rvm_lib_path
   require 'rvm'
   RVM.use_from_path! File.dirname(File.dirname(__FILE__))
 rescue LoadError
   # RVM is unavailable at this point.
   raise "RVM ruby lib is currently unavailable."
 end
end

# If we're using a Bundler 1.0 beta
ENV['BUNDLE_GEMFILE'] = File.expand_path('../Gemfile', File.dirname(__FILE__))
require 'bundler/setup'

# Or Bundler 0.9...
if File.exist?(".bundle/environment.rb")
 require '.bundle/environment'
else
 require 'rubygems'
 require 'bundler'
 Bundler.setup
end

程式碼取自http://blog.ninjahideout.com/posts/the-path-to-better-rvm-and-passenger-integration。它解決了我的問題,乘客與 rvm 配合得很好。

引用自:https://serverfault.com/questions/344670