Saturday, May 17th, 2008...3:08 pm
Deploying Rails on Dreamhost with Phusion Passenger
Deploying Ruby on Rails has always been a pain, even with tools like Mongrel and Capistrano. On shared hosting, it’s nearly impossible. A little while ago, I noticed a project called Phusion Passenger (aka mod_rails), which sought to make deploying as easy as uploading your application to your webhost. A few days ago, Dreamhost (my host) announced on their blog that Phusion Passenger was available on their servers. Naturally, I took some time to play around with it, and so far I’ve been extremely impressed. I threw together a quick app using Viddler.rb and deployed it to Dreamhost (you can see it here). Here’s a quick guide on how to deploy to Dreamhost yourself using mod_rails.
Getting set up
The first thing to do is to set up your domain or subdomain to use Passenger. Just go to the Manage Domains page on the DH web panel, and either create a new domain or edit an existing one. Check the “Ruby on Rails Passenger (mod_rails)?” checkbox and set the web directory to where the public directory of your app will be. Below is a screenshot of my settings for viddler.fidgeting.net.
Next, you need to create your database, so just go into the Manage MySQL section of the panel. Create your database, which should be named as a production database. In my case, it was viddler_production. Then, make sure to change your database.yml to reflect the database you just created.
Uploading and running your application
Before uploading, make sure the first line of your public/dispatch.fcgi has the correct path to ruby on Dreamhost (which is /usr/bin/ruby). Then all you need to do is upload the files to Dreamhost and go to the domain. That’s it—your app is now completely functional. Amazing, huh?
If you need to first run migrations, you can do that from SSH with this command:
RAILS_ENV=production rake db:migrate
If you need to restart your application (anytime you change any files), just run the following command via SSH:
touch tmp/restart.txt
Getting Gems to work on Dreamhost
Since Dreamhost is a shared host, you can’t directly install gems on the server. Dreamhost’s wiki has a lot of information on different ways to get gems working, but they are all fairly involved, and I couldn’t get any of them to work. The way I did it was by unpacking the gems into vendor/gems by using the “gem unpack” command:
gem unpack <GEM NAME>
I’m sure there are better ways to do it, but this method worked perfectly for me.
Overall Impressions
Like I said at the beginning, I’m very impressed with Passenger, and so far I haven’t noticed any issues. The total time for me to deploy was about 20 minutes: way faster than with Mongrel or FastCGI. It’s definitely awesome to see a host as large as Dreamhost using this, and hopefully soon more will follow suit.
Shameless Plug
If you’re looking to use mod_rails on Dreamhost and don’t yet have an account, make sure to use the code MODRAILS when signing up with them for $50 off (the maximum amount).

4 Comments
May 21st, 2008 at 8:45 am
Superb write up.
May 27th, 2008 at 1:16 pm
Hello Kyle, Thanks for that very easy tutorial !
I am having an issue, and it might be linked to the dispatch.fgci ruby address …
The home page of my app is fine, it’s the “Welcome aboard” default page, but when i navigate to a specific action (ex: mySite.com/myController/myMethod/ ) i get a “Ruby on Rails version ‘1.1.2′ not found” error …
In the dispatch file, how exactly should the address be writter (maybe i have a path or synthax prob) ?
May 27th, 2008 at 1:23 pm
Hm, I don’t think that’s a dispatch.fcgi error. It seems like your app is requiring a earlier version of Rails (1.1.2). Check your config/environment.rb and see what RAILS_GEM_VERSION is set to. For me it’s “2.0.2″ (the newest version). You might need to freeze rails–check out this tutorial on how to do it.
1.1.2 is a pretty old version, so you probably want to upgrade to the newest…
May 27th, 2008 at 2:04 pm
Hi again, Thanks for answering, but obviously there’s something else, my baby app seems to not “boot” on the server (as it works perfectly on my local machine)… Will reply if I understand why and how I fix it, for future readers !
Leave a Reply