Deploying your Rails applications with Phusion Passenger

Posted by Raymond Law Tue, 24 Jun 2008 14:00:00 GMT

There have been several methods to deploy an Ruby on Rails application. Until recently, the most popular is to run Apache and proxy balance to multiple Mongrel instances that are running simultaneously.

Passenger, developed by Phusion, is the new kid entering the Rails deployment market. We have been using the Apache PHP module for years and deploying a PHP applications is a snap. This has not been possible with Rails until Passenger. It is so easy too! You can still use Capistrano to automate deployment. I will show you how I get it to work on Ubuntu.

sudo gem install passenger
passenger-install-apache2-module

Update: Phusion just released Passenger 2.0 RC 1. You can download this version and do gem install passenger-1.9.0.gem instead. But I had an error compiling it on Mac OS X Leopard. hongli pointed me to use the version from GitHub that has the fix and it works like a charm. Thanks Phusion guys.

To get it from GitHub:

git clone git://github.com/FooBarWidget/passenger.git

I create a separate /etc/apache2/mods-available/passenger.load and it contains the following:

For 1.0.5:

LoadModule passenger_module /usr/local/lib/ruby/gems/1.8/gems/passenger-1.0.5/ext/apache2/mod_passenger.so
RailsSpawnServer /usr/local/lib/ruby/gems/1.8/gems/passenger-1.0.5/bin/passenger-spawn-server
RailsRuby /usr/local/bin/ruby

For the GitHub version (Of course the path will look different depending on where your git clone is):

LoadModule passenger_module /home/rlaw/downloads/passenger/ext/apache2/mod_passenger.so
PassengerRoot /home/rlaw/downloads/passenger
PassengerRuby /usr/local/bin/ruby

I then tell Apache to load the Passenger module:

a2enmod passenger

Now, I create a virtual host configuration for one of my Rails app in /etc/apache2/sites-available/dealistic:

<VirtualHost *:80>
  ServerAdmin webmaster@dealistic.com
  ServerName dealistic.com

  DocumentRoot /home/deploy/apps/dealistic/current/public

  <Directory /home/deploy/apps/dealistic/current/public>
    Options FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all
  </Directory>

  LogLevel warn
  ErrorLog /var/log/apache2/dealistic/error.log
  CustomLog /var/log/apache2/dealistic/access.log combined
</VirtualHost>

I then restart Apache:

sudo /etc/init.d/apache2 reload

When you need to restart your application because you have changed some code that Rails does not reload in production, just do:

touch /home/deploy/apps/dealistic/current/tmp/restart.txt

I have not tried their Ruby Enterprise Edition yet. They claim substantial memory and speed improvement at RailsConf 2008, so it will be interesting to see.

Using FeedBurner with Typo 1

Posted by Raymond Law Thu, 12 Jul 2007 17:42:00 GMT

You want to run your Typo blog feed through FeedBurner.

First, go to your blog’s admin page and click on the DESIGN tab. Drag the XML Syndication item from Available Items to Active Sidebar items. Choose either RSS 2.0 or Atom 1.0 according to what you choose when setting up FeedBurner. I selected Articles only because that’s what I want. Remember to click on the Publish changes button.

In your Typo app, modify vendor/plugins/xml_sidebar/views/content.rhtml to the following:

  <% if articles -%>
  <li><a href="<Your FeedBurner URL>" rel="alternate" type="application/rss+xml"><img src="http://www.feedburner.com/fb/images/pub/feed-icon16x16.png" alt="" style="vertical-align:middle;border:0"/></a>&nbsp;<a href="<Your FeedBurner URL>" rel="alternate" type="application/rss+xml">Subscribe</a></li>
  <% end %>

Of course you can use whatever image you like. The one shown above is linked to FeedBurner’s standard feed icon. You can use FeedBurner’s Chicklet Chooser to get the HTML code to paste into content.rhtml.

Another way is to set up a redirect using mod_rewrite in your Apache configuration (thanks to Robby):

  # Redirect typo feeds to FeedBurner
  RewriteCond %{HTTP_USER_AGENT} !^FeedBurner.*$
  RewriteRule /xml/(atom|rss|rss20)/feed.xml$ http://feeds.feedburner.com/rayvinly [R=temp,L]

In both cases, make sure you go to your blog admin’s SETTINGS tab, scroll to the bottom and click on Empty Fragment Cache.

Now go to your blog page and click on that Subscribe link to see your FeedBurner feed.