Phusion Passenger (for Dummies!) Phusion Passenger (for Dummies!) ruby-on-rails ruby-on-rails

Phusion Passenger (for Dummies!)


Passenger is a system for preparing and launching instances of Ruby for use with Rack-based applications such as Ruby on Rails. Apache and nginx, the two supported web server platforms, cannot run Ruby like they can PHP, Perl, or Python because there's no built-in Ruby module that works as well as those do. This means Ruby tends to run as an independent group of processes that the web server will have to direct traffic through.

Rails tends to run as a persistent process because the start-up time for the whole stack is significant. Passenger launches new instances as they are required, and will kill off those that are no longer required. You can see this in the process list as they are clearly identified with "Passenger" and "Rails" prefixes.

One feature of Passenger is it will re-use a portion of the Rails stack so that creating additional processes is faster, cloning one instance instead of spinning up a new one from scratch. The loader is written in C++ and handles properly configuring and kicking off each Ruby process as efficiently as possible and also helps save memory by sharing it amongst different processes.

The reason you host things out of the public/ directory is to avoid exposing your application code-base. PHP needs to be configured properly to prevent people from simply browsing directories and downloading the source because there's no specific distinction between static content and executable scripts. A mis-configured server will gladly serve up raw .php files instead of running them, for instance.

Passenger isn't exactly revolutionary, but it does incorporate a number of essential features in a very convenient package. What makes it such a great thing is that it works very well and doesn't demand a lot of attention. Out of the box it's pretty much ready to go.


It serves ruby on rails applications (actually any rack application). I was used with version 2.x of passenger to integrate it directly in apache, but with the new version, which supports standalone execution, I prefer to run it in standalone mode (in conjunction with rvm)

It can be very useful both in development mode and in production mode and it speeds up execution of RoR application.

In order to deploy a RoR application I install it with its own gemset and then I install passenger in that gemset with gem install passenger (you can also safely skip gemsets, but they will isolate the application environment, so it's nice to have them). After that you can start the application with passenger start -a 127.0.0.1 -p 3081 -e production in the project root.

Then I configure an apache vhost to work in reverse proxy mode with a file like this one

<VirtualHost *:80>        ServerName your.server.org        ProxyPass /  http://localhost:3081/        ProxyPassReverse  /  http://localhost:3081/        ProxyRequests     Off        # Local reverse proxy authorization override        # Most unix distribution deny proxy by default (ie /etc/apache2/mods-enabled/proxy.conf in Ubuntu)        <Proxy http://localhost:3081/*>                Order deny,allow                Allow from all        </Proxy></VirtualHost>

and you're ok, you have your application deployed with its local config, it doesn't even need root privileges (for the passenger part).