Is it possible to switch from Ruby 1.8.7 to 1.9.2 when restarting a Rails app that is deployed on Passenger? It should be possible to change PassengerRuby in httpd.conf and restarting Apache. I want to know how it can be done without restarting Apache every time.
More info: We have two different apps, one on Rails 2.3.8 and one on 3.0.5 with the same name, and want to switch between them for testing purposes.
Thanks.
Yes you can switch which versions of ruby you use. Life is easy when you use rvm (http://rvm.beginrescueend.com/). Then you can install the passenger gem in different ruby environments, and when you do it in each environment, the passenger-install-apache2-module command will tell you what to put in the apache config file. For example, mine is now (mac osx - should be similar in other *nixes):
### system ruby and passenger
#LoadModule passenger_module /Library/Ruby/Gems/1.8/gems/passenger-3.0.7/ext/apache2/mod_passenger.so
#PassengerRoot /Library/Ruby/Gems/1.8/gems/passenger-3.0.7
#PassengerRuby /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
### rvm gemset 1.8.7#rails2.3.11 ruby and passenger
LoadModule passenger_module /Users/matt/.rvm/gems/ruby-1.8.7-p334#rails2.3.11/gems/passenger-3.0.7/ext/apache2/mod_passenger.so
PassengerRoot /Users/matt/.rvm/gems/ruby-1.8.7-p334#rails2.3.11/gems/passenger-3.0.7
PassengerRuby /Users/matt/.rvm/wrappers/ruby-1.8.7-p334#rails2.3.11/ruby
I can comment/uncomment the appropriate one and restart apache with the different version of ruby. This also works for ruby 1.9.2 and ruby enterprise edition too.
You don't need a recompile. You just just need to change the PassengerRuby option in the web server. You do need to restart the web server however, just touching restart.txt is not enough.
You can also use Passenger Standalone as a replacement for the Thin/Mongrel/Unicorn reverse proxy setup that bioneuralnet has mentioned. In fact we have a blog post dedicated to running multiple Ruby versions with Passenger Standalone: http://blog.phusion.nl/2010/09/21/phusion-passenger-running-multiple-ruby-versions/
Since Passenger kind of "embeds" itself into Apache, I don't it's possible to switch ruby interpreters without a restart (and possibly even a recompile of Passenger?). To achieve that level of flexibility you may need to look into some kind of reverse-proxy setup involving a stand-alone app server like Thin, Unicorn or Mongrel, running behind Apache or Nginx.
If that's out of the question, then it is strictly possible for Rails 2.3.8 and 3.0.5 apps to both run on Ruby 1.8.7. I have several Rails 3 apps deployed on 1.8.7, though hopefully that will change soon. Assuming your 3.0.5 app doesn't have explicit 1.9 dependencies, why can't you just run them both side by side on 1.8 in separate virtual hosts?
Related
I want to run multiple rubies on our production server. We have some ruby 1.9.3 rails 3.2 sites going live as well as keep older 1.8 sites. I understand that Passenger 3.2 will be able to do this natively but isn't live yet.
So for now, is this the best way to do this?
http://blog.phusion.nl/2010/09/21/phusion-passenger-running-multiple-ruby-versions/
The apache passenger module can't do this. You could however run passenger standalone for each app (with a different ruby version) and then proxy from apache to passenger standalone.
You could of course also proxy to unicorn, thin etc.
What about using multiple VMs/Slices for your different versions of ruby and rails, that way you have more control of your enviroment and don't have to worry about your different rubies/rails causing headaches with each other.
EDIT
Another solution that I have heard of but haven't tried is setting multiple users and running each version of ruby/rails per a different user
I previously had Passenger 2.2.13 install with NGINX 0.7.65 - I want to install rails 3 so I figured I'd go the RVM route. I followed instructions from http://blog.ninjahideout.com/posts/a-guide-to-a-nginx-passenger-and-rvm-server and am having issues because my previous install is in a different location and I think that is the one being used. When I make the changes to my nginx.conf file I get a 502 Bad Gateway on all of my apps..
Can anyone help me out with remove NGINX, Passenger, RVM, and re-installing fresh?
I am running OS X 10.6.
If the previous version was running ruby 1.8, I would do the following to have both apps running:
Install rvm
Replicate current ruby (ruby version, gems, etc) server configuration for rvm.
This is step should include re-installing passenger gem for the new ruby.
Install ruby 1.9 using rvm and then follow this guide: http://blog.phusion.nl/2010/09/21/phusion-passenger-running-multiple-ruby-versions/
I've done this using apache, and now everything is working ok.
This has to do with using RVM and Passenger, passenger by default only has one path for ruby,once updated this worked fine. I've moved away from Passenger locally to avoid dealing with multiple environments.
I have been trying to setup nginx with passenger for a few days now and keep running into problems. When I go to my Rails application with my browser it says: Missing the Rails 2.3.8 gem. Please gem install -v=2.3.8 rails, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.
If I type gem list in my terminal it shows: rails (3.0.0, 2.3.8, 2.3.5)
What is funny is that passenger will find my ruby gems just fine when I use it with Apache on the same machine! But I would like to experiment with nginx because Apache is not doing what I want.
The machine is Ubuntu 10.04 Server
which ruby Shows: /usr/local/bin/ruby (REE)
These are the passenger directives in the nginx.conf:
passenger_root /usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.15;
passenger_ruby /usr/local/bin/ruby;
#Nik Rishav is correct in that you have to be careful when installing Ruby Enterprise Edition (REE) along side the system Ruby. Installing REE incorrectly can cause some very strange things to happen.
While Rails 3.0 could be the cause of your issues, my gut tells me your real issue is one missed step when installing REE. But, just-in-case this doesn't work, a quick Google search will show you any number of good tutorials showing you how to host a Rails app with Phusion Passenger for Nginx. Well, let's give it a go, shall we!
REE runs fine alongside system Ruby, but you have to install it into its own directory. For example:
/opt/ruby-enterprise-X.X.X/bin/ruby
Your other option is to only install REE, but this might not be an option for you. I suspect that when Nginx runs, it does find REE as you have specified it. Did you install Passenger for Nginx from the REE stack?
/opt/ruby-enterprise-X.X.X/bin/passenger-install-apache2-module
If you haven't, you might want to look into that. I'll assume you did.
From your description, it doesn't look like you have told REE where to find your gems. To do this, you need to set REE as the default Ruby Interpreter. To do this, add an entry to the file /etc/environment. On Ubuntu, the directory is /etc/environment. Add REE's bin directory to the PATH environment variable, like this:
PATH="/opt/ruby-enterprise-x.x.x/bin:/usr/local/sbin:/usr/local/bin"
Placing REE first in the PATH will set it as the default Ruby interpreter.
Then restart Nginx, like so:
sudo /etc/init.d/nginx restart
Hopefully this helps. I've had my share of deployment issues and it truly can be frustrating. Wouldn't wish it on anyone...Good luck!
As a check, are you sure your passenger is installed in the correct version of ruby. basically
Both the rubies have separate gems meaning you have to install the other in one..
Check in the /usr/local/lib/ruby/gems/1.8/gems Directory to see if rails 2.3.8 is present. You need to install it in the this ruby.
Both rubies will have separate gem bin files for installation..
possibly /usr/bin/gem is for the system ruby
and /usr/local/bin/gem is for your installation of REE
I would like to know if it's possible to set specific ruby environments to specific sites.
In /etc/httpd/conf/httpd.conf
LoadModule passenger_module /home/user/.rvm/gems/ruby-1.8.7-p249/gems/passenger-2.2.15/ext/apache2/mod_passenger.so
PassengerRoot /home/user/.rvm/gems/ruby-1.8.7-p249/gems/passenger-2.2.15
PassengerRuby /home/user/.rvm/rubies/ruby-1.8.7-p249/bin/ruby
But say I want to use a different ruby environment, for a specific site, how would I go about doing this?
I have rvm installed correctly for my user 'user' so switching environments and installing other environments is quite painless, but the apache configuration side has me clueless.
Thanks
From the RVM Passenger page:
Q: Can I run multiple projects under
passenger with each project on a
different ruby version?
A: Not at this time. Passenger
currently only supports running it's
projects under one ruby. You can get
this behavior using a proxy pass.
If you want different ruby environments per project, you'll need to use mongrel/unicorn/etc.
How would I go about running two separate Rails applications using Phusion Passenger with one using Ruby 1.8.x and the other using Ruby 1.9.x ? I'm running Redmine which isn't Ruby 1.9.x compatible, and the other application is a home grown app.
I'm using Apache 2.2.x with Passenger 2.2.4.
Is this even possible ?
I ended up running Nginx with Passenger and Ruby 1.9 on port 80, and then proxying off my other virtual hosts to Apache 2.2 on port 8080 with Passenger and Ruby 1.8. Win!
Just a little late but I found this thanks to Google: Phusion Passenger & running multiple Ruby versions Must be the necromancer in me.
Use the PassengerRuby directive.
Passenger supports multiple Ruby interpreters as of version 4.0.0 (February 2013). The PassengerRuby config option has been made a per-virtual host option, so you can customize your Ruby interpreter on a per-application basis. See here for details.