Multiple Rubies with a single Passenger
Until Phusion Passenger released version 4 you had to choose a single Ruby to run Passenger with and all applications running on it had to be written in that Ruby. That method is clean and ideal. Unfortunately when managing multiple legacy applications things can't always be so clean.
I was recently moving an old app (i.e. Ruby 1.8.7, Rails 2.x, Mongrel) to a new server but didn't have the time to upgrade the app to a 1.9/3.x version. Luckily after reading the updated Passenger documentation I discovered that as of 4.x, Passenger now allows for multiple versions of Ruby to run the same version of Passenger. To make this work:
-
Install Passenger with Ruby on Apache the normal way:
gem install passenger passenger-install-apache2-module
-
And, following the directions, copy the directives to a global Passenger config (possibly in
conf.d/passenger.conf
orhttpd.conf
depending on your configuration):LoadModule passenger_module /home/myuser/.rvm/gems/ruby-1.9.3-p125/gems/passenger-4.0.2/libout/apache2/mod_passenger.so PassengerRoot /home/myuser/.rvm/gems/ruby-1.9.3-p125/gems/passenger-4.0.2 PassengerDefaultRuby /home/myuser/.rvm/wrappers/ruby-1.9.3-p125/ruby
-
PassengerDefaultRuby
has to be defined at the global level, but thePassengerRuby
directive now can be defined at any level (i.e. VirtualHost, Directory, Location, .htaccess). So I changed my VirtualHost for this app to the following:<VirtualHost *:443> … RailsBaseURI /myapp <Directory /apps/myapp> Options -MultiViews PassengerRuby /home/myuser/.rvm/wrappers/ruby-1.8.7-p371/ruby </Directory> … </VirtualHost>
Notice the
PassengerRuby
directive. It defines Ruby 1.8.7 for this specific app. So, yes, Passenger 4 was installed with Ruby 1.9.3, but because the gem supports multiple Ruby versions this local definition allows it to work with this 1.8.7 app.Also notice the difference between
RailsBaseURI
for Rails 2.x apps andRackBaseURI
for Rails 3.x apps.
Related Links
Written by Barnaby Alter
Related protips
1 Response
Hi, I was using rails1.8.7 and ruby2.3.15 for 'testsite1' app. I'm created new app 'testsite2' using ruby2.0.0 and rails4.0.0. To make it work simultaneously, I'm using RVM with 2.0.0 as default ruby and passenger installed on it. Below are the configuration for the APACHE and PASSENGER:
PASSENGER.CONF:
PassengerRoot /home/MYUSER/.rvm/gems/ruby-2.0.0-p247/gems/passenger-4.0.23
PassengerDefaultRuby /home/MYUSER/.rvm/wrappers/ruby-2.0.0-p247/ruby
PASSENGER.LOAD:
LoadModule passengermodule /home/MYUSER/.rvm/gems/ruby-2.0.0-p247/gems/passenger-4.0.23/buildout/apache2/mod_passenger.so
APACHE CONFIGURATION FILE:
<VirtualHost *:80>
ServerName 192.168.12.124
DocumentRoot /home/MY_USER/public
ErrorDocument 404 /404.html
RailsEnv development
RailsBaseURI /testsite1
<Directory /home/MYUSER/testsite1>
PassengerRuby /home/MYUSER/.rvm/wrappers/ruby-1.8.7-p374/ruby
Allow from all
Options -MultiViews
</Directory>
RailsBaseURI /testsite2
<Directory /home/MY_USER/testsite2>
Allow from all
Options -MultiViews
</Directory>
</VirtualHost>
'testsite2' is working as expected, but 'testsite1' is trying to use ruby2.0.0 (ignoring the apache configuration attribute PassengerRuby). If I provide the 'PassengerRuby' attribute outside the <Directory> tag, 'testsite2' stops working and 'testsite1' works perfectly.
Please help me on this.