I've got a server that predominantly runs Ruby 1.8.7, but now I have a Rails 3.2 app that needs 1.9.3. I've installed Passenger 4 as it supports the ability to run multiple Rubies on a per-virtual server basis.
However, it appears that while you can assign a particular Ruby, the application doesn't have access to that Ruby's gemset. So I have my virtual server configured with the 1.9.3 Ruby, as confirmed on the error page my application now gives:
Ruby interpreter command
/home/aaron/.rvm/rubies/ruby-1.9.3-p0/bin/ruby
But the GEM_HOME parameter tells a different story:
GEM_HOME = /home/aaron/.rvm/gems/ruby-1.8.7-p352
Looking through the configuration directives for Passenger 4, I see no way to specify a different gemset. Am I missing something, or is this thing just not ready for prime time?
From your gemset dir run:
$ passenger-config --ruby-command
It will tell you ruby path for Apache and Nginx.
Command: /home/deric/.rvm/wrappers/ruby-2.0.0-p247#my_gemset/ruby
Version: ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-linux]
To use in Apache: PassengerRuby /home/deric/.rvm/wrappers/ruby-2.0.0-p247#my_gemset/ruby
To use in Nginx : passenger_ruby /home/deric/.rvm/wrappers/ruby-2.0.0-p247#my_gemset/ruby
Nginx: For Passenger 4 you can specify multiple ruby versions. So for specific server config:
your_site.conf:
server {
listen 80;
root /home/aaron/web/public;
passenger_enabled on;
passenger_ruby /home/aaron/.rvm/wrappers/ruby-2.0.0-p247#your_gemset/ruby;
}
nginx.conf: (this works for new passenger 4.0.17)
http {
passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini;
}
Just run from your gemset dir this:
$ passenger-status
It will check whether passenger_native_support.so is available. Depending on your RVM installation, you might need to run it with rvmsudo
$ rvmsudo passenger-status
For Debian/Ubuntu there are now binary packages of nginx and passenger available which makes the installation much easier.
As Tombart pointed out: If you use the precompiled Passenger modules (in my case for for Apache2) you end up with a system up and running.
However, if using RVM I stumbled upon the fact that you need to use the "wrapper directory" to select the correct RVM ruby version and gemet like so in your Apache vhost config:
PassengerRuby /home/of_your_ruby_user/.rvm/wrappers/ruby-x.y.z-p123#gemset/ruby
This way Passenger knows how to find the correct gemset relative to this directory (../../gems/ruby-x.y.z-p123#gemset/gems). Otherwise Passenger would use the "standard ruby gemset" which is odd if you want to run multiple apps with the same ruby version. I can only guess that this is similar for Nginx.
Related
I have a ROR app (version 6.1.4.1) with Ruby 2.7.4 on a Raspberry Pi 4 with 4 GB RAM and a 32 GB SD card. I installed Passenger 6.0.12 using the tarball installation and am running it with nginx. passenger start in the app directory works successfully, but when I try running it as with nginx (/opt/nginx/sbin/nginx) on port 80, I get the above error when visiting the site.
I'm accessing the app via IP address, which is configured in the nginx.conf and the app is installed in /home/pi/src/bogie_can. There is a .bundle directory with a config file in the app directory, and that's where the gems are installed. I'm running the app in "development" mode, which is configured in the server section of the nginx.conf file using passenger_app_env.
The specific error is that the app cannot find racc-1.5.2. The Bundler info is #<struct Bundler::Settings::Path explicit_path="/home/pi/src/bogie_can/.bundle", system_path=false, default_install_uses_path=false>.. So, we note that the .bundle path is correct and in the .bundle/ruby/2.7.0/gems/ directory, racc-1.5.2 is indeed installed and owned by the user "pi".
I've cleared out old bundle installations and tried switching the app user from pi to root (which was nobody) and back. Also, I'm using rbenv, so I also ran rbenv rehash after the fresh bundle install. I've also carefully reviewed the "Detailed diagnostics" from the Passenger error page (which is super helpful!) and do not see anything that is obviously wrong.
Using the Passenger error page as a guide, it seems that:
The gems are indeed installed as needed
The user, either root or pi, have permissions to access the gems
pi is a reasonable user to run the app
The passenger_root and passenger_ruby are coming from the passenger-config about subcommands and are verified as well.
At this point, there must be some configuration I've overlooked or gotten wrong and I would greatly appreciate some questions and pointers.
I found the root cause of the problem.
I had set passenger_ruby to the result of passenger-command about ruby-command, which gave me:
passenger-config was invoked through the following Ruby interpreter:
Command: /usr/bin/ruby2.7
Version: ruby 2.7.4p191 (2021-07-07 revision a21a3b7d23) [arm-linux-gnueabihf]
To use in Apache: PassengerRuby /usr/bin/ruby2.7
To use in Nginx : passenger_ruby /usr/bin/ruby2.7
To use with Standalone: /usr/bin/ruby2.7 /usr/src/passenger-6.0.12/bin/passenger start
The following Ruby interpreter was found first in $PATH:
Command: /home/pi/.rbenv/shims/ruby
Version: ruby 2.7.4p191 (2021-07-07 revision a21a3b7d23) [arm-linux-gnueabihf]
To use in Apache: PassengerRuby /home/pi/.rbenv/shims/ruby
To use in Nginx : passenger_ruby /home/pi/.rbenv/shims/ruby
To use with Standalone: /home/pi/.rbenv/shims/ruby /usr/src/passenger-6.0.12/bin/passenger start
I was using /usr/bin/ruby2.7 and having the problem with racc not being found. I switched it to use the rbenv shim and Passenger was able to correctly find all the gems in the [APP_ROOT]/.bundle/ directory
I also cleared out the default nginx installation, which was still trying to be started with nginx.service and then added my own /etc/init.d/nginx script and added it to the init.d database so that it now starts with the OS.
I'm trying to deploy a Ruby On Rails App on a shared host, that has ruby 1.9.3-p551. Phusion Passenger now returns the error message:
Rails 4 prefers to run on Ruby 2.1 or newer.
You're running
ruby 1.9.2p0 (2010-08-18 revision 29036) [x86_64-linux]
Please upgrade to Ruby 1.9.3 or newer to continue.
(SystemExit)
/.../my_home_directory/.../vendor/cache/gems/railties-4.2.3/lib/rails/ruby_version_check.rb:12:in `abort'
and then a big stack trace. I'm using rbenv for controlling different ruby versions. When I type in rbenv versions it says:
system
* 1.9.3-p551 (set by /my_home_directory/.rbenv/version)
ruby -v
1.9.3p551 (2014-11-13 revision 48407) [x86_64-linux]
But in the error message of passenger there's the information:
General Interpreter Information
RUBY_VERSION = 1.9.2
I can't check the Apache config files because I'm on a shared host and have therefore no root rights. So I can't reinstall ruby or rubygems.
I already tried reinstalling every local gem. I typed bundle install and bundle upgrade multiple times. I tried to install a local ruby version with rbenv local 1.9.3-p551 in the home directory, the .rbenv directory, the app home and the app/public directory. I tried to change the used ruby version with rbenv shell 1.9.3-p551, and probably did some more things, I currently can't remember because I started very late to write the things down that I already did.
Why does passenger have the wrong ruby versions besides that PassengerRuby in the Apache config file is wrong? I think that's very unlikely, because I think that my hosting provider knows what he's doing. Is there something I could do to let passenger or rails use the right (installed) version?
Does anybody have an idea why passenger has the wrong ruby versions besides that PassengerRuby in the Apache config file is wrong?
Passenger author here. The fact that PassengerRuby in the config file is wrong, is the only reason why you're having this problem. The only solution is to set PassengerRuby to the right instance.
If your shared host doesn't allow you to set PassengerRuby, then I recommend that you switch to a different. Try Digital Ocean for example. They're cheap, gives you full control, and we have a full end-to-end deployment walkthrough for Digital Ocean.
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?
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.
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