Passenger ('Bundler:RubyVersionMismatch') - ruby-on-rails

I'm having a problem with deploying my rails app on my server. I'm deploying using Passenger for serving up pages. The following error is listed on my page when I start the server. It seems like the version of passenger I have installed is referencing ruby 1.8.7 but my app has been built in 2.0.0. I've tried removing ruby 1.8.7 and reinstalling Passenger, but no luck so far. If I run ruby -v from my directory it lists the version as 2.0.0.
Your Ruby version is 1.8.7, but your Gemfile specified 2.0.0 (Bundler::RubyVersionMismatch)
/home/ubuntu/.rvm/gems/ruby-2.0.0-p0#global/gems/bundler-1.3.4/lib/bundler/definition.rb:361:in ` validate_ruby!'
/home/ubuntu/.rvm/gems/ruby-2.0.0-p0#global/gems/bundler-1.3.4/lib/bundler.rb:116:in `setup'
/home/ubuntu/.rvm/gems/ruby-2.0.0-p0#global/gems/bundler-1.3.4/lib/bundler/setup.rb:17
/usr/lib/ruby/vendor_ruby/1.8/rubygems/custom_require.rb:59:in `gem_original_require'
/usr/lib/ruby/vendor_ruby/1.8/rubygems/custom_require.rb:59:in `require'
/var/lib/gems/1.8/gems/passenger- 4.0.0.rc4/lib/phusion_passenger/loader_shared_helpers.rb:212:in `run_load_path_setup_code'
/var/lib/gems/1.8/gems/passenger-4.0.0.rc4/helper-scripts/rack-preloader.rb:73:in `preload_app'
/var/lib/gems/1.8/gems/passenger-4.0.0.rc4/helper-scripts/rack-preloader.rb:127
My apache2.conf file has the following additions:
Include sites-enabled/
<ifmodule mod_ssl.c>
NameVirtualHost *:443
</ifmodule>
LoadModule passenger_module /var/lib/gems/1.8/gems/passenger 4.0.0.rc4/libout/apache2/mod_passenger.so
PassengerRoot /var/lib/gems/1.8/gems/passenger-4.0.0.rc4
PassengerRuby /usr/bin/ruby1.8
Edit: ANSWER
I was using sudo to install passenger and apache2 module. Should have just typed:
gem install passenger -pre
passenger-install-apache2-module
WITHOUT sudo.

your passenger config is pointing to ruby 1.8
LoadModule passenger_module /var/lib/gems/1.8/gems/passenger 4.0.0.rc4/libout/apache2/mod_passenger.so
PassengerRoot /var/lib/gems/1.8/gems/passenger-4.0.0.rc4
PassengerRuby /usr/bin/ruby1.8
It should probably look something like this...
LoadModule passenger_module /var/lib/gems/2.0.0/gems/passenger 4.0.0.rc4/libout/apache2/mod_passenger.so
PassengerRoot /var/lib/gems/2.0.0/gems/passenger-4.0.0.rc4
PassengerRuby /usr/bin/ruby2.0.0
Passenger installation is very helpful and it prints these lines for you on the console after successful installation. You should just copy those lines and paste them into your apache conf

You should try install passenger again.

This is why I switched from using RVM to RBENV. You won't run into this problem with RBENV. Plus its just better.
If you upgrade ruby using RVM on your production server, you'll be forced to reinstall passenger/nginx (in your case it looks like just passenger).
Huge pain, and causes server downtime.
Use RBENV instead to save yourself this headache. With RBENV/Capistrano, upgrading can simply be done via your gemfile, and the rest just works.

Related

passenger 4 and apache is not using the right ruby version

I've installed passanger to run as apache module, I installed passenger with gem install passenger as my user ruby in a rvm gemset while running ruby 2.1.2.
On apache this is my main configuration for passenger:
LoadModule passenger_module /home/ruby/.rvm/gems/ruby-2.1.2/gems/passenger-4.0.50/buildout/apache2/mod_passenger.so
<IfModule mod_passenger.c>
PassengerRoot /home/ruby/.rvm/gems/ruby-2.1.2/gems/passenger-4.0.50
PassengerDefaultRuby /home/ruby/.rvm/gems/ruby-2.1.2/wrappers/ruby
PassengerResolveSymlinksInDocumentRoot on
</IfModule>
My project uses a different ruby version and I want to use it, so on my virtualhost I'm setting PassengerRuby
PassengerRuby /home/ruby/.rvm/gems/ruby-2.2.1#estas/wrappers/ruby
It exists, and I can use that ruby#gemset to launch for example rails console.
But when I go to the url it raises an error complaining about missing gems.
Could not find rake-10.4.2 in any of the sources (Bundler::GemNotFound)
/home/ruby/.rvm/gems/ruby-2.1.2/gems/bundler-1.7.2/lib/bundler/spec_set.rb:92:in `block in materialize'
....
Ruby interpreter command
/home/ruby/.rvm/gems/ruby-2.1.2/wrappers/ruby
Environment variables
rvm_bin_path = /home/ruby/.rvm/bin
GEM_HOME = /home/otheruser/deploy/shared/bundle/ruby/2.1.0
SHELL = /bin/bash
IRBRC = /home/ruby/.rvm/rubies/ruby-2.1.2/.irbrc
PASSENGER_DEBUG_DIR = /tmp/passenger.spawn-debug.XXXXU7p7Dp
MY_RUBY_HOME = /home/ruby/.rvm/rubies/ruby-2.1.2
PATH = /home/ruby/.rvm/gems/ruby-2.1.2/bin:/home/ruby/.rvm/gems/ruby-2.1.2#global/bin:/home/ruby/.rvm/rubies/ruby-2.1.2/bin:/home/ruby/.rvm/gems/ruby-2.2.1#myproject/bin:/home/ruby/.rvm/gems/ruby-2.2.1#global/bin:/home/ruby/.rvm/rubies/ruby-2.2.1/bin:/home/ruby/.rvm/bin:/usr/local/jdk/bin:/home/otheruser/perl5/bin:/usr/local/jdk/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/X11R6/bin:/root/bin:/usr/local/bin:/usr/X11R6/bin:/home/otheruser/bin
Im curious about the PATH, why does it has both ruby-2.1.2 and ruby-2.2.1? when running passenger, what sets this PATH?
What I'm doing wrongly or why this is not working? I'm doing this project to learn about capistrano and passenger, any help will be greatly appreciated.

Is it possible to change Passenger Ruby version without recompiling?

I tried changing the default ruby command to 1.9.2 but Passenger keeps running 1.8.7
Is Passenger compiled with Ruby embedded?
To set the Ruby version add this line to your vhost file:
PassengerRuby /path/to/the/ruby/version/you/want/to/use
Whenever a "bundle update" updates the version of the passenger gem, I do
sudo su -
passenger-install-apache2-module
At the end of that process, it spits out the full blob of stuff that you need to put at the top or your Apache config. E.g. something like:
LoadModule passenger_module /usr/local/rvm/gems/ruby-1.9.2-p180#rails31/gems/passenger-3.0.9/ext/apache2/mod_passenger.so
PassengerRoot /usr/local/rvm/gems/ruby-1.9.2-p180#rails31/gems/passenger-3.0.9
PassengerRuby /usr/local/rvm/wrappers/ruby-1.9.2-p180#rails31/ruby
I update the blob of stuff, restart Apache and all seems well.
I imagine that this same process is necessary after updating Ruby.
Set PassengerRuby before the <Directory> tag.
Example:
PassengerRuby /home/ubuntu/.rvm/wrappers/ruby-2.3.1/ruby
It is working for me!
Find more detail in this post.

Ruby on Rails 3 + Apache2 + Phusion Passenger: Bundler::GemNotFound exception

I'm trying to deploy a Rails app on an Apache2 server by using Phusion Passenger. While everything works well locally, I am getting the infamous "Bundler::GemNotFound" error while deploying:
Could not find abstract-1.0.0 in any of the sources (Bundler::GemNotFound)
All my gems are installed in my local home folder. Thus the passenger configuration lines from my Apache2 configuration file are as follows:
LoadModule passenger_module /home/regis/.gem/gems/passenger-3.0.7/ext/apache2/mod_passenger.so
PassengerRoot /home/regis/.gem/gems/passenger-3.0.7
PassengerRuby /usr/bin/ruby1.8
I understand you would need more information to analyse the issue at hand, but I have no idea on how to diagnose this further.
Try doing bundle install --path vendor/cache

installing passenger on Apache2 using rvm

I've installed Apache2 and it runs okay.
And I've installed rvm following this link.
After that, I've execute follow commands as its order. Actually some of these commands are from this link installing redmine.
rvm install 1.8.7
rvm use 1.8.7
gem install rails -v=2.3.5
gem install postgres-pr pq
gem install i18n -v=0.4.2
gem install passenger
passenger-install-apache2-module
and append this to apache2.conf
LoadModule passenger_module /home/myhome/.rvm/gems/ruby-1.8.7-p330/gems/passenger-3.0.2/ext/apache2/mod_passenger.so
PassengerRoot /home/myhome/.rvm/gems/ruby-1.8.7-p330/gems/passenger-3.0.2
PassengerRuby /home/myhome/.rvm/wrappers/ruby-1.8.7-p330/ruby
This is log for Apache after restart
[notice] Apache/2.2.16 (Ubuntu) PHP/5.3.3-1ubuntu9.3 with Suhosin-Patch Phusion_Passenger/3.0.2 configured -- resuming normal operations
But!!!, if I open my redmine root page, it just shows file list in public directory. I think Passenger may not work correctly.
Why? and how to fix this? I've tried everything what I can do for 2 days T-T
Have you added this section to apache config? It tells apache that you are using Rails application:
<VirtualHost :*80>
ServerName myapp
DocumentRoot /root-to-your-path/public
</VirtualHost>
And restarted Apache? Read more here: http://www.modrails.com/documentation/Users%20guide%20Apache.html#_deploying_a_ruby_on_rails_application
You should view the Passenger Integration guide from RVM, or the more detailed guide from Phusion (the makers of Passenger).
Note that in Phusion's guide, you should omit the --pre when installing the gem, as the guide was written when Passenger 3 was still in beta.

Passenger / REE can't find rails, it's in the $PATH, what gives?

I've got a fresh install of Ruby EE (1.8.6-20090610) and Passenger (2.2.5) on Debian Lenny. REE is installed in /opt/ruby-enterprise and it is added to the $PATH of all users through /etc/environment, and PassengerDefaultUser is set to root. The problem is when loading a rails app, the Passenger error says the rails 2.3.3 gem is missing. However it was installed with Passenger and a rails -v as root says it's there. What could be going wrong?
Found the error:
PassengerRuby /usr/bin/ruby1.8
should have been
PassengerRuby /opt/ruby-enterprise/bin/ruby

Resources