Phusion Passenger 4 ignores setenv GEM_PATH - ruby-on-rails

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 :)

Related

Using passenger to run both Rails 3.0 and Rails 3.1 app (using different rvm gemsets)

I just followed these directions for installing a new rvm gemset and installing rails-3.1.0.rc2 on my local machine. At first I was getting a Passenger error saying the rake-0.9.2 gem could not be loaded, but I found this reminding me to run "$ passenger-install-apache2-module". It installed fine prompted me to add the following to my Apache config file (/etc/apache2/httpd.conf):
LoadModule passenger_module /Users/robs/.rvm/gems/ruby-1.9.2-p180#rails-3.1/gems/passenger-3.0.7/ext/apache2/mod_passenger.so
PassengerRoot /Users/robs/.rvm/gems/ruby-1.9.2-p180#rails-3.1/gems/passenger-3.0.7
PassengerRuby /Users/robs/.rvm/wrappers/ruby-1.9.2-p180#rails-3.1/ruby
However, there are already three lines there from a different gemset:
LoadModule passenger_module /Users/robs/.rvm/gems/ruby-1.9.2-p180#rails-3.0/gems/passenger-3.0.7/ext/apache2/mod_passenger.so
PassengerRoot /Users/robs/.rvm/gems/ruby-1.9.2-p180#rails-3.0/gems/passenger-3.0.7
PassengerRuby /Users/robs/.rvm/wrappers/ruby-1.9.2-p180#rails-3.0/ruby
If I leave both sets of lines there uncommented (the #rails-3.1 gemset's is last), and restart Apache, my Rails 3.0 app won't start. I find myself having to comment out the rails 3.1 gemset lines, restart Apache, and then run "$ rvm use ruby-1.9.2-p180#rails.3.0". If I want to run the Rails 3.1 app, I have to do the opposite.
Is there a way to have both be able to run at the same time without these extra steps?
This article could be useful for you.
I used it as an example to setup my own development environment with nginx.
You could tell Passenger to use ruby 1.9.2 without a gemset, then in each of your apps run rvm use ruby-1.9.2-p180 and bundle install. This means your base ruby-1.9.2-p180 will have the gems for both applications, and bundler should handle limiting the gems available to your application.
End result:
ruby-1.9.2-p180 has gems for both apps
ruby-1.9.2-p180#rails-3.0 has gems for your 3.0 app
ruby-1.9.2-p180#rails-3.1 has gems for your 3.1 app
passenger is using ruby-1.9.2-p180
bundler should still limit the gems available to each application
both apps should work

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?

Installing passenger in production environment

I have managed to install ruby 1.9.2 with rvm and rails,, but am having some trouble getting passenger installed. I have the source files in my /opt directory. When I run sudo ./passenger-install-nginx-module in the passenger bin directory I get this error: /usr/bin/env: ruby: No such file or directory
rvm info:
Ruby Path "/home/me/.rvm/rubies/ruby-1.9.2-p180/bin/ruby"
Use rvmsudo instead of sudo to run the passenger install command. Also, you may need to specify the full path to that command. On my server it's something like this:
rvmsudo /usr/local/rvm/gems/ruby-1.9.2-p290/gems/passenger-3.0.11/bin/passenger-install-apache2-module
You should be able to generate an RVM wrapper script (shell script to select RVM ruby):
rvm wrapper default_192
...and then set PassengerRuby in your Passenger config (tell Passenger which ruby to use):
PassengerRuby /home/your_user/.rvm/bin/default_192
if ever you find yourself wondering why your vagrant box has suddenly stopped loading your website, and you have the passenger gem installed, there's a big possibility that it has automatically upgraded the gem and needs you to make a few changes to the apache module for it. This is just one issue I have come across.
So in light of sharing the knowledge just open the following file for editing on the command using your preferred editor if you're running apache.
/etc/apache2/conf.d/passenger
and replace the three lines with the following:
. LoadModule passenger_module /var/lib/gems/1.9.1/gems/passenger-4.0.10/buildout/apache2/mod_passenger.so
PassengerRoot /var/lib/gems/1.9.1/gems/passenger-4.0.10
PassengerDefaultRuby /usr/bin/ruby1.9.1
we're basically replacing the version number the module should use.

Passenger with Nginx cannot find rails 2.3.8 gem

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

How to configure ruby on rails with Apache

i have strugle in connection between J2me and ruby on rails under Webrick server...
dats why i need configure with apache..i saw some tutorials about configuring..but it's not working..
You need to install Phusion Passenger: http://www.modrails.com/
Also, for performance improvement, do install REE: http://www.rubyenterpriseedition.com/
What environment are you coming from? Unix, Mac, Windows? Let's assume you're using some Unix variant, as you should, and Apache2 is already properly installed:
1 - install phusion passenger:
$ gem install passenger
2 - install passenger-apache2-module:
$ passenger-install-apache2-module
Be sure to read what the passenger-install-apache2-module command output is telling you, in the end it will give you some lines you have to put in some apache configuration files, if you miss that, it won't work. At all.
3 - Edit your vhosts.conf file (under /etc/apache2/) to define a hostname for your application, point to your application's public folder, etc.
VirtualHost examples
4 - Profit.
Commands listed under 1. and 2. might need admin privileges, it all depends on how your environment is set.
WebRick is not for production environments at all, in fact, it's not really good for development either, if you intend on doing some slightly more complex stuff with your rails applications. Other than that, you didn't really give enough detail about your problem, so I hope this answer at least points you in the right direction.

Resources