Installing passenger in production environment - ruby-on-rails

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.

Related

Gem path error in Ruby on Rails

I'm relatively new to Ruby on Rails.
I have an issue when I try to run the app. I get the following errror:
* ERROR *: Cannot execute /usr/local/rvm/wrappers/ruby-1.8.7-p174#soda/ruby: No such file or directory (2)
This is true; there is no such directory. There is a file called
/usr/local/rvm/wrappers/ruby-1.8.7-p174#DACE/ruby - which is exactly the gem file I want to use.
As I understand it, the .rvmrc file specifies the directory for the gem file. In this case, however, the .rvmrc has the following:
rvm --create use "ruby-1.8.7-p174#DACE"
Furthermore, rvm info statues that /usr/local/rvm/gems/ruby-1.8.7-p174#DACE is in fact the gem path.
So, why does it think it should be looking for this non-existant path?
Thanks in advance,
Tim
Run a rvm current to see which version of ruby and which gemset you are using. Then run rvm gemset list to see which gemsets do you have created. If soda is not listed, then do a rvm gemset create soda to create this gemset.
Remove this .rvmrc file and then create another one. (This won't break anything on your project, just the project reference of ruby and gems would be deleted).
You can read this answer to help you understand better how rvm works, there is a link there:
How to make rvmrc file in project root folder?
I encountered the same problem while setting up rails production machine with Nginx & Passenger. Here's how I solved the problem.
Make sure passenger gem is installed then cd into project directory and run the following command
passenger-config build-native-support --help
Which will give you output similar to following:
Usage: passenger-config build-native-support [OPTIONS]
Phusion Passenger utilizes a Ruby native extension, called
native_support, for improving Ruby performance. The extension
depends on the Phusion Passenger version and the Ruby version.
Normally, every time you run a Phusion Passenger version with a Ruby
version that it hasn't encountered before, it will rebuild the
native_support library for that Ruby version. By running this
command, you can force the native_support to be built for the
current Ruby interpreter.
The current Ruby interpreter is:
Path: /home/deploy/.rvm/gems/ruby-x.x.x#gemset/wrappers/ruby
Version: 2.1.5
Options:
-h, --help Show this help
Now copy the Path from output and paste it into nginx configuration file. In my case it was located at /etc/nginx/nginx.conf
passenger_ruby /home/deploy/.rvm/gems/ruby-x.x.x#gemset/wrappers/ruby
And finally restart the server or run your deployment script.

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.

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

why isn't my rails install using the latest version of passenger?

I'm using VirtualBox on Windows to run an Ubuntu OS, which is running the turnkey rails package, which comes with ruby 1.8, rails 2.3.8, and passenger 2.2.5. When I first booted it up with just a vanilla rails app it worked fine, but now I'm getting the following error:
uninitialized constant PhusionPassenger::Utils::PseudoIO::StringIO
I googled this, and on the phusion/google groups it said this was an old error and to upgrade passenger, which I did with gem upgrade passenger. It said it was installing passenger 2.2.15, but it doesn't appear to be using it. I re-started the whole virtualbox and it is still giving me the same error, with the backtrace showing passenger-2.2.5.
I realize there are several layers here and plenty of places for things to go wrong, and to add to that, I'm pretty much a Linux newb. I've got some experience with rails. I'd appreciate any help.
It could well be your Apache configuration file. When Passenger installs it adds some code to the /etc/apache2/http.conf file so that Apache loads the Passenger extension. This code includes the version number so if you've changed the version of Apache you'll need to modify this file. The code you're looking for looks like this
LoadModule passenger_module /opt/local/lib/ruby/gems/1.8/gems/passenger-2.2.15/ext/apache2/mod_passenger.so
PassengerRoot /opt/local/lib/ruby/gems/1.8/gems/passenger-2.2.15
PassengerRuby /opt/local/bin/ruby
You'll have to be authenticated to edit the file so open a terminal window and type
sudo gedit /etc/apache2/http.conf
and enter your password to edit the file. Once you've made the changes close gedit then run
sudo /etc/init.d/apache2 restart
to restart Apache and try your Rails application again.
Try using
gem list
to make sure the new version was installed. Next to the passenger gem should see more than version listed.
You can use
gem clean
to remove old versions.

I have two versions of Ruby (1.8.7 and 1.9) installed how to specify which one for rails? or does it matter

I have Ruby 1.8.7 and 1.9 install. I run the different ones by specifying ruby or ruby1.9 when running commands. for example
ruby --version
or
ruby1.9 --version
however when I want to create new rails application the command available is rails such as:
rails my_app_name
How do I specify when I call the 'rails' command to create new rails app or does it matter? I mean if I create it with one version it will be the same code of the other version or does the generator script user different code for different Ruby versions.
Thanks,
Tam
The simplest way is to use the -S option.
For example and according to your case, to use Ruby 1.9 you can do:
# Create new Rails project with Ruby 1.9
ruby1.9 -S rails new_app
# Run the project with Ruby 1.9
ruby1.9 script/server
#install new gems for Ruby 1.9
ruby1.9 -S gem install some_gem
# Use Rake with Ruby 1.9
ruby1.9 -S rake something
And as your default Ruby interpreter is the 1.8.7 one, then just keep the normal use of it, no need for -S option.
I use passenger/mod_rails for development locally (on Mac OSX Snow Leopard). In the apache (or nginx) conf file where passenger's settings live, you set a "PassengerRuby" environment variable. You can point this to whichever ruby installation you're wanting to use (don't forget to restart apache afterwards).
I'm using RVM at the moment for managing my ruby installations. In my user's apache conf file I've got the default Mac OSX snow leopard 1.8.7 set up with passenger, and then also one for a 1.8.6 installation via RVM. Whichever one I want to use is left un-commented.
Here's how it looks at the moment:
# Default passenger
LoadModule passenger_module /Library/Ruby/Gems/1.8/gems/passenger-2.2.5/ext/apache2/mod_passenger.so
PassengerRoot /Library/Ruby/Gems/1.8/gems/passenger-2.2.5
PassengerRuby /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
# Use RVM 1.8.6 ruby
# LoadModule passenger_module /Users/dylanfm/.rvm/gems/ruby/1.8.6/gems/passenger-2.2.5/ext/apache2/mod_passenger.so
# PassengerRoot /Users/dylanfm/.rvm/gems/ruby/1.8.6/gems/passenger-2.2.5
# PassengerRuby /Users/dylanfm/.rvm/bin/ruby-1.8.6-p383
Doesn't matter, the rails structure is quite the same.
For unix type OSes. You could also link executables for ruby1.8/1.9 to ruby, gem1.8/1.9 to gem and etc.
Something like:
ln -sf /usr/bin/ruby1.8 /usr/bin/ruby
ln -sf /usr/bin/gem1.8 /usr/bin/gem
...
You can find paths to your ruby/gem/rake/etc. executables by using which command. You could alias these commands as use18, use19 for example.

Resources