Multiple production ruby/rails environments - ruby-on-rails

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.

Related

Phusion Passenger 4 ignores setenv GEM_PATH

I wanted to (finally) update my Passenger install from version 3 to 4, but I'm having some trouble setting the GEM_PATH env variable as I did with v3.
In my Apache configuration I have the following line, telling passenger where to find my rvm gemsets (note #my_set):
SetEnv GEM_PATH "/.../.rvm/gems/ruby-1.9.3-p448#my_set:/.../.rvm/gems/ruby-1.9.3-p448#global"
This works fine with Passenger v3. However when I switch to version 4, the application fails to load and the debug view shows the following:
GEM_PATH = /.../.rvm/gems/ruby-1.9.3:/.../.rvm/gems/ruby-1.9.3-p448#global
Which seems to be the system default.
Setting any other ENV variable using setenv works. For example I added the line
SetEnv TEST_VAR "FOO"
to my apache configuration and it turned up in the passenger debug view without a hitch:
TEST_VAR = "FOO"
It feels like Passenger is specifically overwriting my GEM_PATH environment variable somehow. There's no mention of this in the docs as far as I can tell. Any thoughts would be greatly appreciated.
You can do this one other way. Since you are using Rails in version 3 or 4 with bundler, you can make bundler isolate all gems for application on a production server putting copies of them into application folder. To do that issue:
bundle install --deployment
You can read more about it in Bundler Deployment documentation
You can also read up on how to make RVM work with Passenger 3 (it might be transferrable to 4) with gemsets, though in my opinion, using bundler deployment is much better option.
I am not sure it will help you but, instead of considering the GEM_PATH, maybe you should consider the PassengerRuby and the PassengerDefaultRuby configuration
http://www.modrails.com/documentation/Users%20guide%20Apache.html#PassengerRuby
Passenger is certainly trying to use the default ruby of your system, and you have to tell it to use the good one, that is to say the one yuo installed with RVM. To find the correct ruby, in your console, be sure that the ruby you are using is the one you want to use, you can type
ruby -v
which ruby
rvm list
rvm use [the one you want to use]
Once you are sure that in this terminal session, the ruby you are using is the on you want passenger to use, type this command
passenger-config about ruby-command
You should then see a line like :
To use in Apache: PassengerRuby /home/tommyjam/.rvm/gems/ruby-2.1.1/wrappers/ruby
Copy the interesting information and paste it in the good location, that is to say, as the passenger doc say
PassengerRuby may occur everywhere: in the global server configuration, in <VirtualHost>, in <Directory>, in <Location>, and in .htaccess if AllowOverride Options is on
You can also change PassengerRuby to PassengerDefaultRuby and put it in the global server configuration, which is, I think in the /etc/apache2/mods-available/passenger.conf
Hope it will help you :)

Running Multiple Versions of Passenger for Multiple Ruby-on-Rails Applications

After I install the Passenger Apache2 module, it gives me something like:
LoadModule passenger_module /home/passenger/.rvm/gems/ruby-1.9.2-p290/gems/passenger-3.0.17/ext/apache2/mod_passenger.so
PassengerRoot /home/passenger/.rvm/gems/ruby-1.9.2-p290/gems/passenger-3.0.17
PassengerRuby /home/passenger/.rvm/wrappers/ruby-1.9.2-p290/ruby
(Sorry, I have a user account called passenger. Don't be confused.)
So if I want to deploy another rails app that uses totally different version of ruby, then I believe it will give something similar with above configurations BUT with different ruby version, for example:
LoadModule passenger_module /home/passenger/.rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.17/ext/apache2/mod_passenger.so
PassengerRoot /home/passenger/.rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.17
PassengerRuby /home/passenger/.rvm/wrappers/ruby-1.9.3-p194/ruby
Then how can I config the Apache2 (I'm NOT asking the Virtual Host part)? Because there are two versions of LoadModule passenger_module. I don't think one Apache2 server can load two different versions of passenger_module, right?
I'm so confused. Please help me out.
Passenger supports multiple Ruby interpreters as of version 4.0.0. The PassengerRuby config option has been made a per-virtual host option, so you can customize your Ruby interpreter on a per-application basis.
For passenger 3 you would have to use proxies.
For passenger 3.x :
One solution from phusion is to use mod_proxy to bind to passenger standalone : http://blog.phusion.nl/2010/09/21/phusion-passenger-running-multiple-ruby-versions/
I'm not sure at 100%, but at 99%, you can't load two version of passenger module, because they will conflict espacially for the configuration variable like PassengerRoot, PassengerRuby which are limited to the server scope

Multiple Rubies under apache in production server

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

Correct way to set up Rails environment?

Thanks Tilo for your response. I will try to ask a better question.
I need to set up a Ruby on Rails Production environment that will only be used to host RoR applications and will be used as a Git server too. There will be no development done to these applications on the Production server. Right now, I forsee the production server hosting a maximum of 5 to 6 applications only. A couple will be company internal only and the rest of the apps will be viewable to the public. The traffic that they will receive is about 12 to 20 hits per week.
I have been given access to a Virtual Machine that will be the Production server and is currently running Ubuntu 10.04 LTS, Apache2, MySQL, and Passenger. There will be two RoR developers using the Production server to host their applications.
My Development Environment of which I am running Ubuntu 10.04 LTS, Apache2, and MySQL on my own laptop looks like this for each project/application:
RVM installed per application, Git,
Ruby 1.9.2 installed thru rvm, Rails
3.0.3, and I have yet to install the Capistrano gem.
My question is I don't understand how to host a RoR application on our production server.
As an example of what might be done to host a RoR application: I am surmising that I will create a user called app1 under the home directory. Next, should I install Ruby system wide or should I install rvm for app1 and then Ruby for app1? What are the steps involved on how to set-up the environment to run an application on a production server?
Can you give me a few setup scenarios, please?
Thanks in advance.
You didn't tell us what you want to use this web-site for... is it company internal only?
just a few users? or is it externally facing the internet? Just one server running everything?
If it's facing the internet, I would certainly stay away from Ubuntu... look at CentOS/RedHat or FreeBSD to install on a production server.
I'd definitely use Capistrano for deployment. Definitely Git.
I would definitely not install RVM system-wide - IMHO it is not robust enough.
I emailed with Wayne Seguin (maker of RVM) and he also uses the method I've outlined in the post below,
using one dedicated deploy user:
For how to deploy ruby-versions and gems with RVM, look at this post:
Installing Ruby offline using rvm
If you really need two versions of Ruby for two different apps, then use two deploy-users!
Each of them has their own default-ruby-version(!) that's why you really need two users :)
and you can install / manage the gems for each project separately under each of the deploy accounts.
You should also put the git repository in each of the accounts, so you can test.

Switch ruby when restarting rails app deployed on Passenger

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?

Resources