Ramaze + Phusion Passenger

October 2, 2008 at 14:14

Filed under: Computing — Pistos @ 14:14

As some of you may know, I am a relatively active member of the Ramaze community. I have seen an increase in incidents of people asking for help getting Ramaze to run under Phusion Passenger. I decided to see just how hard the setup would be, with the intention of documenting it for the Ramaze community. I succeeded in running a basic Hello World application, so here are the steps I took.

Create a simple Ramaze app

Even if you have an existing Ramaze app that you will use instead of this little demo app, you should read this section because I talk about important pitfalls that can cause things to break. You can apply the same ideas to your app.

As per the Passenger User’s Guide, I created a tmp/ directory under the root of the Ramaze app. Passenger needs this directory (see the User Guide if you want to know why). I also made a public/ directory, which is a standard part of Ramaze apps in general.

Afterwards, I crafted a basic one-file Ramaze app in start.rb (the standard filename for the executable in Ramaze apps), and a config.ru file, which is needed by Rack. (Rack is the interface layer between Ramaze and Apache.)

start.rb

require 'ramaze'
class MainController < Ramaze::Controller
  def index
    'hi'
  end
end

A critical thing to note about this Ramaze app is that there is no Ramaze.start command. If you put it, the whole jalopy will fall apart — so don’t put that in your app. If you have a legacy app that you want to start running under Passenger, comment out or remove the existing Ramaze.start line.

config.ru

require 'start'
Ramaze.trait[:essentials].delete Ramaze::Adapter
Ramaze.start!
run Ramaze::Adapter::Base

This is the standard “rackup” file that comes with Ramaze. I didn’t make any changes to it, but I should point out that the rackup file that was shown on the Passenger site was out of date.

Overview

So, to recap, my basic little app had these four things:

  public/
  tmp/
  config.ru
  start.rb

Install Passenger

If you are intending to run a Ramaze app under a web host that already offers Passenger to its users, you can obviously skip this section.

As per the Install page of the Passenger website, I simply ran

  gem install passenger

and

  passenger-install-apache2-module

I did this as root, but it looks possible to do so as a non-root user. The Passenger installation script was straight forward, and required no interaction on my part other than to confirm my desire to proceed with the installation. It is sufficiently verbose enough for you to see it compile and install things under your /usr/lib/ruby tree. When it’s done, it clearly displays some lines for you to put into your Apache configuration file. In my case:

 LoadModule passenger_module /usr/lib/ruby/..../mod_passenger.so
 PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-2.0.3
 PassengerRuby /usr/bin/ruby18

I obediently pasted that into the main Apache config. It then shows a sample virtual host configuration that you can use as a skeleton:

 <VirtualHost *:80>
    ServerName www.yourhost.com
    DocumentRoot /somewhere/public
 </VirtualHost>

I copied that into my virtual host config file, and adjusted the hostname and changed the document root to the full, absolute path of the public/ directory of my Ramaze app.

Restart Apache

I restarted Apache to get all my configuration changes active.

Run the app

At this point, my Ramaze app was ready to run under Passenger, so I browsed to http://myhostname and saw “hi” displayed, as expected. To see a little detail (or to troubleshoot problems), examine your Apache logs. You should see all output from Ramaze piped there.

I hope this helps people who are trying to run Ramaze under Passenger! If you need further assistance please visit our support channel, #ramaze on the FreeNode IRC network, or try the discussion group.

Share This

Related posts:

  1. Ramaze by Example - Part 0: Installation and Preparation
  2. Ramaze by Example - Part 10: Cosmetics
  3. Ramaze by Example - Part 2: Base Application
  4. Ramaze by Example - Part 3: Model
  5. Ramaze by Example - Part 5: Controller

1 Comment »

  1. Comment by Pistos — October 3, 2008 @ 07:07

    manveru tells us that the following config.ru lets you use Ramaze.start in the start.rb as well:

    config.ru

    require 'ramaze'
    Ramaze.skip_start
    require 'start'

RSS feed for comments on this post. TrackBack URI

Leave a comment

You may use Markdown syntax in your comment.

Powered by WP Hashcash

Powered by WordPress.
Close
E-mail It
Socialized through Gregarious 42