William Notowidagdo Kiranatama Staff
Knowledge


The case is you got single server and need to run foo.com on Ruby Enterprise Edition and bar.com on Ruby 1.9.2. Not to worry, RVM to the rescue! Oh btw, in this post I use Apache and Rails 3.0.10.

Setting up foo.com

Install and use Ruby Enterprise Edition
$ rvm install ree
$ rvm use ree
Install Passenger
$ rvm gemset use global
$ rvm gem install passenger
$ passenger-install-apache2-module
Load Passenger from Apache
$ sudo nano /etc/apache2/mods-available/passenger.load
then insert below
LoadModule passenger_module /home/user/.rvm/gems/ree-1.8.7-2011.03/gems/passenger-3.0.9/ext/apache2/mod_passenger.so
PassengerRoot /home/user/.rvm/gems/ree-1.8.7-2011.03/gems/passenger-3.0.9
PassengerRuby /home/user/.rvm/wrappers/ree-1.8.7-2011.03/ruby
In your .rvmrc file on your Rails app directory
rvm --create use  "ree-1.8.7-2011.03@foo.com"
and create config/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')
    $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
Now setup Virtual Host for foo.com
<VirtualHost *:80>
    ServerName foo.com
    DocumentRoot /home/user/public/my-projects/foo.com/public
    <Directory /home/user/public/my-projects/foo.com/public>
        Allow from all
        Options -MultiViews
    </Directory>
</VirtualHost>
then enable it, restart your server and visit foo.com to check your setup is fine.

Setting up bar.com

For bar.com, we will use a standalone Passenger. Install and use Ruby 1.9.2
$ rvm install 1.9.2
$ rvm use 1.9.2
Install Passenger
$ rvm gemset use global
$ rvm gem install passenger
Then start Passenger from you Rails app directory
$ passenger start -a 127.0.0.1 -p 3000 -e production -d
Now setup Virtual Host for bar.com
<VirtualHost *:80>
    ServerName bar.com
    DocumentRoot /home/user/public/my-projects/bar.com/public
    PassengerEnabled off
    ProxyPass / http://127.0.0.1:3000
    ProxyPassReverse / http://127.0.0.1:3000
</VirtualHost>
then enable Apache mod_proxy module
$ sudo a2enmod proxy proxy_balancer
lastly, enable bar.com and restart Apache. Your newly setup bar.com should ready. Got better trick? let me know!