RVM和Passenger有两个Ruby版本

时间:2012-05-04 13:35:46

标签: ruby-on-rails rvm passenger ruby-1.9 ruby-1.8

如何使用带有1.9和1.8(ree)ruby版本的Passenger,RVM和Apache?我需要它在生产环境中。 我试试这个:RVM PASSENGER但是REE才有效。 1.9说这个:

  

给定的红宝石环境需要ruby-1.9.2-p318(相对于   ree-1.8.7-2012.02)(RVM :: IncompatibleRubyError)

来自1.9 ruby​​版本的我的文件: .rvmrc

environment_id="ruby-1.9.2-p318"

if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
  && -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
then
  \. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
  [[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]] &&
    \. "${rvm_path:-$HOME/.rvm}/hooks/after_use" || true
  if [[ $- == *i* ]] # check for interactive shells
  then echo "Using: $(tput setaf 2)$GEM_HOME$(tput sgr0)" 
  else echo "Using: $GEM_HOME" 
  fi
else
  rvm --create use  "$environment_id" || {
    echo "Failed to create RVM environment '${environment_id}'."
    return 1
  }
fi

setup_load_paths.rb

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

  ENV['BUNDLE_GEMFILE'] = File.expand_path('../Gemfile', File.dirname(__FILE__))
  require 'bundler/setup'

的httpd.conf

...
LoadModule passenger_module /usr/local/rvm/gems/ree-1.8.7-2012.02/gems/passenger-3.0.12/ext/apache2/mod_passenger.so
   PassengerRoot /usr/local/rvm/gems/ree-1.8.7-2012.02/gems/passenger-3.0.12
   PassengerRuby /usr/local/rvm/wrappers/ree-1.8.7-2012.02/ruby

...

1 个答案:

答案 0 :(得分:0)

您可以查看这篇精彩的文章:Phusion Passenger & running multiple Ruby versions

基本上,您可以使用rvm和反向代理来完成它。例如,您可以像往常一样部署一个ruby版本(如1.9),并使用反向代理设置另一个:

  • rvm使用1.8
  • gem install passenger --pre
  • cd / path / to / your / app
  • 乘客开始-a 127.0.0.1 -p 3000 -d
  • 在apache config中设置反向代理

    <VirtualHost *:80>
      ServerName www.hamburgers.com
      DocumentRoot /path/to/your/app/public
      PassengerEnabled off
      ProxyPass / http://127.0.0.1:3000
      ProxyPassReverse / http://127.0.0.1:3000
    </VirtualHost>
    

您也可以尝试使用独角兽代替乘客,或者用ngix替换apache。