Rails deployment is so easy these days

22 November 2008, 12:04, by Colin

I have been meaning to blog about Phusion Passenger for a while as about 3-4 months ago we migrated Stubmatic from using Apache / Mongrel Cluster to Phusion Passenger A.K.A. mod_rails.

Mod rails is extreamly easy to install. Make sure you update gem first:

gem update --system

Then install the Phusion Passenger gem

gem install passenger

Once complete you can run the Phusion Passenger install that compiles mod_rails for you.

passenger-install-apache2-module

Once this completes it will give you some code to past into your httpd.conf file and you are ready to start configuring your sites.. Well actually if you have been using Mongrels then time to strip most of the configuration out of your https.conf file. You can have as simple a configuration as shown below. Note: The DocumentRoot should be set to the public folder within your app. Passenger automatically detects that this is a rails app.

    ServerName www.stubmatic.com
    DocumentRoot /websites/stubmatic/public

One thing to note is that by default Passenger disables ModRewrite for that VirtualHost and in our case we use ModRewrite for a number of things such as providing a Maintenance page when maintenance.html is in our public folder allowing us to take the app offline. We also use ModRewrite to hide .svn folders, so we needed to use ModRewrite. Thankfully Passenger provides a solution. Note: You must first make sure you remove the .htaccess file in your rails public folder!

So our new Apache configuration looks like this:

    ServerName www.stubmatic.com
    DocumentRoot /websites/stubmatic/public
 
    RailsAllowModRewrite on
 
    RewriteEngine On
 
    RewriteRule ^(.*/)?.svn/ - [F,L]
 
    RewriteCond %{DOCUMENT_ROOT}/maintenance.html -f
    RewriteCond %{SCRIPT_FILENAME} !maintenance.html
    RewriteRule ^.*$ /maintenance.html [L]

If you want to setup an Apache / Phusion Passenger testing server you will also need to add the following directive to your VirtualHost configuration:

RailsEnv development

As you can see Phusion Passenger make deployment of Ruby on Rails as trivial as deploying a PHP. You can easily reload Phusion Passenger by running the following command from within your Rails project root.

touch tmp/restart.txt

In terms of performance, Phusion Passenger holds it’s own against Mongrel and there are plenty of details on Phusion’s website.

For more information:

  1. Phusion Passenger
  2. Phusion Passenger Documentation


There are no comments yet.



Leave a comment

About Colin

Colin remembers the days when people tried to make you pay for web browsers, and when Internet Explorer was considered the best option for the future of the web. Things have changed a lot since then, in fact Colin regularly shakes his head when he thinks what is possible online in 2009. His co-authored book, Learning Ext JS shows off some of the technologies he loves working with when he’s not writing on his personal blog or preparing a pet project in our labs.

Go Tripod Ltd

Go Tripod Ltd is a UK-based development company working with some of the most exciting software technologies around. Simon Ashley, Jon Baker and Colin Ramsay are the brains behind projects such as Stubmatic, and are developing bespoke web, mobile and desktop software for clients with household names. We believe in good service as well as good software, and we’re eager to work with people who feel the same.