Capistrano Recipe to Install or Update Passenger

Update:

  • the basic installation can be done via “passenger-install-apache2-module –auto”
  • a better script that does the whole job can be found in cap-recipes

Took me some minutes to figure this out, so here for your laziness-pleasure (for Ubuntu):

Usage
To install passenger or update to the newest release:
cap install_passenger

Install

#deploy.rb
  desc "Install Passenger"
  task :install_passenger do
    install_passenger_module
    config_passenger
  end

  desc "Install Passenger Module"
  task :install_passenger_module do
    sudo "gem install passenger --no-ri --no-rdoc"
    input = ''
    run "sudo passenger-install-apache2-module" do |ch,stream,out|
      next if out.chomp == input.chomp || out.chomp == ''
      print out
      ch.send_data(input = $stdin.gets) if out =~ /(Enter|ENTER)/
    end
  end

  desc "Configure Passenger"
  task :config_passenger do
    version = 'ERROR'#default
    #passenger (2.0.3, 1.0.5)
    run("gem list | grep passenger") do |ch, stream, data|
      version = data.sub(/passenger \(([^,]+).*/,"\\1").strip
    end

    puts "    passenger version #{version} configured"

    passenger_config =<<-EOF
      LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-#{version}/ext/apache2/mod_passenger.so
      PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-#{version}
      PassengerRuby /usr/bin/ruby1.8
    EOF

    put passenger_config, "src/passenger"
    sudo "mv src/passenger /etc/apache2/conf.d/passenger"
  end

Source
Basic recipe