Multiple Rubies on one server

I had the ‘joy’ of upgrading to Rails3 recently. The Rails application wasn’t the problem, but making it work alongside another Rails 2.3 application on my server was tough and gave me many headaches. Having multiple ruby- and rails versions proofed to be tricky. There is documentation, but I just couldn’t get my head around it, so I just want to sum up some of my pitfalls and give pointers.

Few words about my setup. I have a Debian server running apache2 with Passenger 3. My system Ruby is 1.8 and my goal was to have one application run on Ruby 1.8.2 (and Rails 2.3) and one on 1.9.2 (and Rails 3.0)

RVM

Ruby Version Management is cool for development and also nice for running multiple environments of Ruby. In my case one with the old Ruby 1.8.7 and a new one for Ruby 1.9.2. You can use rvm on your server, however it does not work as smooth with Passenger as you’d hope. RVM has some very good documentation, but the bit about Passenger failed to tell me what I need. In essence my misconception was, that you’d tell the system-wide Passenger configured in apache to switch to the rvm gemset. It tries to do this, but fails, as it’s still executed by the system-ruby-binary, not the ruby-binary within the rvm set. This means, you have just one rvm gemset from which you can run your app via Passenger within apache. For more Rails applications with different rvm gemset, you need to start them as Passenger Standalone and add them as ProxyPass in the apache2 virtualhosts. This is well described in the Phusion Passenger blog and untangled the knot in my brain!

ProxyPass

So I set up my Rails app as Passenger standalone as described in the article above. I used RAILS_ENV=production to pass the correct environment:

I got a few apache errors as my ProxyPass was not configured correctly. Nothing a good search engine and a look at /var/log/apache2/error.log couldn’t help.

With one exception. My resources, stylesheets, pictures weren’t loaded. The log gave this message:

proxy: DNS lookup failure for: localhost:3000stylesheets returned by /stylesheets/screen.css

This one was nasty, and there weren’t many helpful answers on the net, probably because the solution is so simple when you know whats wrong. My hint: It’s a missing / in the virtualhosts config of the ProxyPass.

Leave a reply

Your email address will not be published.

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>