Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Problem: Apache/Passenger don't recognize RVM

I have a multi-user install of RVM, per the canonical instructions: http://beginrescueend.com/rvm/install/

I then edited /etc/profile.d/rvm.sh to include the following line so that Ruby 1.9 is the version used for all users logged in:

rvm use --default 1.9.2

I have at least 3 users on my system:

  • ubuntu (the default user I use to perform all interactive tasks)
  • passenger (this is the user for deploy tasks)
  • www-data (this is presumably the user I set up to serve httpd requests)

When logged in interactively to ubuntu and passenger, the following returns correctly:

$ ruby -v
ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-linux]

However, the www-data user, which actually serves these requests, never executes /etc/profile.d/rvm.sh (or anything in profile.d, for that matter). As a result, the following always happens when logged in as the www-data user:

$ ruby -v
ruby 1.8.7 (2010-08-16 patchlevel 302) [x86_64-linux]

As a result of this, Bundler runs just fine on my development sandbox with the right Ruby version, but craps out with a "Could not install Gem on Ruby 1.8" type of error when running:

$ cap deploy
<snip>
  * executing "cd /var/www/app/releases/20111031001406 && bundle install --gemfile /var/www/app/releases/20111031001406/Gemfile --path /var/www/app/shared/bundle --deployment --quiet --without development test"
servers: ["example.com"]
[example.com] executing command
</snip>

(example.com and app are placeholders for my real server and application)

The error I receive is to the tune of "The linecache gem requires Ruby > 1.9)" which is how I know that Ruby 1.9.2 not running is the problem.

How do I get Apache to recognize RVM and the Ruby version I want? (RVM and the Ruby I want are installed, per the multi-user pattern, within /usr/local/rvm

I have followed every instruction I can think of many times over, but I'm clearly missing something here. Any guidance here would be deeply appreciated.

FWIW, this is my Capistrano deploy script:

# if you're still using the script/reapear helper you will need
# # these http://github.com/rails/irs_process_scripts
#
# # bundler bootstrap
require 'bundler/capistrano'

set :nice_name, "App"
set :application, "app"
set :domain, "example.com"

role :web, "#{domain}"                          # Your HTTP server, Apache/etc
role :app, "#{domain}"                          # This may be the same as your `Web` server
role :db,  "#{domain}", :primary => true # This is where Rails migrations will run
# # server details
set :default_run_options, {:pty => true}
set :ssh_options, {:forward_agent => true, :keys => "/path_to/ssh.key"}
#ssh_options[:keys] = [File.join(ENV["HOME"], ".ssh", "id_rsa")]

set :deploy_to, "/var/www/#{application}/"
set :user, "passenger"
set :use_sudo, false 

# repo details
set :scm, :git
set :scm_username, "githubuser"
set :repository, "git://github.com/githubuser/app.git"
set :branch, "master"
set :git_enable_submodules, 1

# tasks
namespace :deploy do
  task :start, :roles => :app do
    run "touch #{current_release}/tmp/restart.txt"
  end

  task :stop, :roles => :app do
  # Do nothing.
  end

  desc "Restart Application"
  task :restart, :roles => :app do
    run "touch #{current_release}/tmp/restart.txt"
  end

  desc "Symlink shared resources on each release - not used"
  task :symlink_shared, :roles => :app do
    #run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
  end
end

namespace :passenger do
  desc "Restart Application"  
  task :restart do  
    run "touch #{current_path}/tmp/restart.txt"  
  end
end

after :deploy, "passenger:restart"
after 'deploy:update_code', 'deploy:symlink_shared'
share|improve this question

1 Answer 1

up vote 1 down vote accepted

You probably need to set up the PassengerRoot and PassengerRuby directives to point to the version of ruby you want it to use (the one controlled by RVM). If you're not doing so already, I'd also recommend using one gemset per app. You may decide to install passenger into whatever gemset you wish, as long as the apache directives are set correctly.

Example (using ree and Ubuntu):

sudo apt-get install build-essential bison openssl libreadline5 libreadline5-dev curl zlib1g zlib1g-dev libssl-dev libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev  autoconf libc6-dev ncurses-dev libmysqlclient15-dev apache2-prefork-dev apache2-mpm-prefork libapr1-dev libaprutil1-dev libcurl4-openssl-dev 
rvm use ree@${gemset_here} --create --default --passenger
rvm ree@${gemset_here} gem install passenger --version="${PASSENGER_VERSION}"
passenger-install-apache2-module --auto --apxs2-path $(which apxs2)

You may need to get the appropriate build dependencies for your distro. After passenger compiles, you'll need to make sure you configure it (check the output). If you need the apache conf snippet to use, run this:

passenger-install-apache2-module --snippet

I put mine in /etc/apache2/conf.d/passenger.conf (on an Ubuntu system). Your config dir may vary depending on distro. If you still get problems at this point, it may be that you need to fix some permissions on the RVM gemset directories you are using.

share|improve this answer
    
Thanks @TrinitronX. I think I am setting PassengerRoot and PassengerRuby, but maybe incorrectly. I will take a look at it again. –  Manu R Nov 8 '11 at 19:17

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.