Is it possible to change Passenger Ruby version without recompiling? - ruby-on-rails

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.

Related

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

Passenger ('Bundler:RubyVersionMismatch')

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.

Ruby/Rails Apache2 & Passenger setup returning directory listing

It's worth nothing, first of all, that I've got a fully-functional Apache2 server (on a Ubuntu 12.04 VPS) with multiple working virtual hosts (but this is my first attempt to deploy a Rails site). Additionally, the Rails site I'm trying to launch is fully functional on my local WEBRick server.
I've referenced various online instructions for making Apache, Ruby, Rails & Passenger play nice together, including:
This from Linode, my host (they don't offer documentation specific for 12.04)
This from O'Reilly
The Passenger documentation that's part of the installation process of passenger-install-apache2-module
The online Passenger documentation
Various old SO questions such as this and this
To summarize, so far I've:
Installed Ruby (ruby -v in site root returns 1.9.3), RVM, Ruby Gems, Rails (rails -v in app folder returns 3.2.8 and I can start a rails server in the app folder) & Passenger (including all dependencies)
As instructed by passenger-install-apache2-module, I've added the following lines to the bottom of /etc/apache2/apache2.conf:
LoadModule passenger_module /var/lib/gems/1.8/gems/passenger 3.0.17/ext/apache2/mod_passenger.so
PassengerRoot /var/lib/gems/1.8/gems/passenger-3.0.17
PassengerRuby /usr/bin/ruby1.8
Created & enabled (it's listed in /etc/apache2/sites-enabled/) a virtual host /etc/apache2/sites-available/foo.com that contains the following:
<VirtualHost *:80>
ServerName foo.com
DocumentRoot /home/user/public/foo.com/public
<Directory /home/user/public/foo.com/public>
AllowOverride all
Options -MultiViews
</Directory>
</VirtualHost>
Uploaded my Rails app to /home/user/public/foo.com/
Did a bundle install in /home/user/public/foo.com/
On my local OSX machine, I've add xxx.xxx.xxx.xxx foo.com [the VPS IP] to /etc/hosts.
Restarted Apache
But when I navigate to foo.com in the browser, I simply see a listing of /home/user/public/foo.com/public. Also, there are no recent entries in the Apache error.log. However, whenever I restart Apache I get:
* Restarting web server apache2
[Fri Oct 26 00:04:12 2012] [warn] module passenger_module is already loaded, skipping
... waiting [Fri Oct 26 00:04:13 2012] [warn] module passenger_module is already loaded, skipping
...done.
I'm hoping I've overlooked something really stupid. Any help figure out what that is would be much, much appreciated. Thanks!
If you're working with apache2.2, you should not include the following in apache2.conf
LoadModule passenger_module /var/lib/gems/1.8/gems/passenger 3.0.17/ext/apache2/mod_passenger.so
PassengerRoot /var/lib/gems/1.8/gems/passenger-3.0.17
PassengerRuby /usr/bin/ruby1.8
Instead you should create 2 files on /etc/apache2/mods-available:
passenger.load with:
LoadModule passenger_module /var/lib/gems/1.8/gems/passenger3.0.17/ext/apache2/mod_passenger.so
passenger.conf with:
PassengerRoot /var/lib/gems/1.8/gems/passenger-3.0.17
PassengerRuby /usr/bin/ruby1.8
Finally you just run:
a2enmod passenger
And it's done. By the way, when you make it work you might consider using a more recent version of ruby (1.9.3... or so). The best way to do that is using RVM.
I was trying to use passenger to run a Rails 2.3. app I had created a couple of years ago and needed to move to a new server.
I added passenger, but all I got was a directory listing.
In the end it turned out that I did not have a config.ru file.
It was enough to create a file with those two lines:
require File.dirname(__FILE__) + '/config/environment'
run ActionController::Dispatcher.new
It took me about 5 hours to find out I was missing those two lines. I am wishing everybody in a similar situation that he/she will find this answer before spending too much time on this... :-)
Had the same problem, turned out, that in /etc/apache2/mods-enabled/passanger.load I had the apache2 installed passenger.so that didn't want to work, changed it to the gems installed passenger.so
LoadModule passenger_module /var/lib/gems/1.9.1/gems/passenger-4.0.20/buildout/apache2/mod_passenger.so

Rails Passenger problem with Apache2

I'm trying to setup a ruby on rails server on ubuntu10.10 with apache2 and mod_rails (Phusion Passenger).
I already installed ruby 1.9.2-p0 and rails 3.0.8 and installed Passenger with the passenger-install-apache2-module and the passenger gem (v3.0.7).
It then tells me to add 3 lines to my Apache config file. So I added these lines to '/etc/apache2/apache2.conf':
LoadModule passenger_module /usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.7/ext/apache2/mod_passenger.so
PassengerRoot /usr/local/lib/gems/1.9.1/gems/passenger-3.0.7
PassengerRuby /usr/local/bin/ruby
And I edited my '/etc/apache2/httpd.conf' and added:
NameVirtualHost *:80
<VirtualHost *:80>
ServerName 192.168.0.2
DocumentRoot /var/www/webop/public
<Directory /var/www/webop/public>
Allow from all
Options -MultiViews
</Directory>
</VirtualHost>
I also found out that the file mod_passenger.so in /usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.7/ext/apache2/ actually does not exist, its name is mod_passenger.c. But I don't get any errors from that.
The server should only be accessible through a LAN. When I access the server I see all the files and directories in the public folder of my app but the app itself does not get started.
When I restart apache it tells me that mod_rails is already loaded so I guess that passenger is running but I can't figure out why it doesn't start my app!
Thanks in advance!
The reason mod_passenger.so does not exist is because you haven't installed the Apache module. Execute:
passenger-install-apache2-module
This will create the mod_passenger.so file inside your gem directory, and give you three lines to copy into your apache2.conf file.
The passenger module is installed in your current gemset so you shouldn't get any conflicts between projects. You can use any compatible version of Ruby, and any gemset you like, via RVM, and possibly also RBENV. This makes for a nice easy upgrade path from one version of Ruby to the next.
I finally figured out what the problem was: I messed up my ruby installation.
In /usr/local/ I had ruby1.9.2-p0 installed (which was the version I wanted to use) but in /usr/ i had ruby1.8.7 installed.
Passenger was confused which ruby version to use so I changed the LoadModule, PassengerRoot and PassengerRuby paths within apache2/mods-enabled/passenger.load and .config to the correct paths and it finally worked! Both files were created automatically which also caused the problem of a redefinition: On apache startup there was a warning 'mod_passenger already loaded'. So I removed
LoadModule passenger_module /usr/local/lib/ruby/gems/1.9.1/gems/passenger-3.0.7/ext/apache2/mod_passenger.so
PassengerRoot /usr/local/lib/gems/1.9.1/gems/passenger-3.0.7
PassengerRuby /usr/local/bin/ruby
from the apache config and the warning disappeared!
Probably this will help someone else some day!
I have come across a cleaner solution today. This might help future users. The command -
passenger-install-apache2-module
tells me to put these three lines in apache configuration file.
LoadModule passenger_module /home/anwar/.rvm/gems/ruby-2.2.0/gems/passenger-4.0.59/buildout/apache2/mod_passenger.so
<IfModule mod_passenger.c>
PassengerRoot /home/anwar/.rvm/gems/ruby-2.2.0/gems/passenger-4.0.59
PassengerDefaultRuby /home/anwar/.rvm/gems/ruby-2.2.0/wrappers/ruby
</IfModule>
But, where is that configuration file? The answer is the configuration files are seperated into many pieces and they reside in /etc/apache2/mods-available.
So you should do three things -
Create a file ending with .load in /etc/apache2/mods-available folder. I used passenger.load.
Paste the three lines in that file and save the file.
Now in terminal use sudo a2enmod <module-conf-filename> to enable the module. In my case, the file was, passenger.load. So, I used
sudo a2enmod passenger
Now, restart the server and use the command apache2ctl -M to find that passenger module is enabled.
I think they want you to put those three lines in your httpd.conf file, not in your apache2.conf. At least that's how I've always done it.

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.

Resources