Installing Rails on Dreamhost
July 15th, 2007
This tutorial will explain the process of installing a Ruby On Rails app on a dreamhost server (using FastCGI).
There are few “rails on dreamhost” guides out there, and i’m sure there are lots of you ‘dreamhosters’ that wants to install a working rails app.
The un-official documentation written on this is undoubtedly the dreamhost wiki. http://wiki.dreamhost.com/index.php/Ruby_on_Rails
You can use this guide, and it might work, it changes often, but in all my cases, it wouldn’t work correctly, and i would end up with numerous 500 errors.
why would you use my guide instead of the dh wiki guide? because if the dh wiki guide doesn’t work for you, you have no one to ask for help work through your issue, conversely, if my guide doesn’t work, you can b!tch and moan to me and i’ll help you get your rails app up and update this guide if need be. and i have screenshots wink
note: Dreamhost is NOT the greatest rails hosting company, but they are my favorite web hosting company hands down… their customer support is finer than the competition by far, so it’s worth it to me to be loyal to dh.
So here is a quick setup guide that works for me, and i’ve followed this process to setup many (FastCGI) rails sites already… never a flaw so far. and sure, it might not be the “most secure way to set it up” but honestly, i haven’t had a problem with that, so it’s not even an issue at this point.
this assume that your web root is empty and ready to serve files, and if it’s not empty, that you backed up all your files to start clean and fresh.
remember to replace “raboof” with your own application name
SSH into your box to install a rails app
make sure you have a ssh user setup in dreamhost

if you are on win*, you might need to download Putty ssh client

if you are on nix, you probably already have a ssh client, just open a terminal and type *ssh -l username yourwebsite.com

login to yourwebsite.com
create your rails app using the name of your app, for example: raboof
$cd raboof.com $rails raboof
Setup your app to use FastCGI rails on dreamhost
- edit your .htaccess file to use fastcgi.
$cd raboof/public $nano -w .htaccess
find the line that says
RewriteRule ^(.*)$ dispatch.cgi [QSA,L]
and change it to read
RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
your whole .htaccess file should look like this.
AddHandler fastcgi-script .fcgi AddHandler cgi-script .cgi Options +FollowSymLinks +ExecCGI RewriteEngine On RewriteRule ^$ index.html [QSA] RewriteRule ^([^.]+)$ $1.html [QSA] RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ dispatch.fcgi [QSA,L] ErrorDocument 500 "<h2>Application error</h2>Rails application failed to start properly" DirectorySlash Off
now save and exit nano, ctrl+x , y (to save changes), [enter] (to confirm the filename and exit nano)
- edit your dispatch.fcgi
first open up dispatch.fcgi for editing with nano (-w is so your lines don’t wrap)
$nano -w dispatch.fcgi
make sure you are pointing to the correct ruby binary
the first line should read
#!/usr/bin/ruby
your entire dispatch.fcgi looks like this
#!/usr/bin/ruby require File.dirname(__FILE__) + "/../config/environment" require 'fcgi_handler' class RailsFCGIHandler private def frao_handler(signal) dispatcher_log :info, "asked to terminate immediately" dispatcher_log :info, "frao handler working its magic!" restart_handler(signal) end alias_method :exit_now_handler, :frao_handler end RailsFCGIHandler.process!
now save and exit nano
- make sure your dispatch.rb file is using the correct ruby binary path mine looks like this
#!/usr/bin/ruby require File.dirname(__FILE__) + "/../config/environment" unless defined?(RAILS_ROOT) require "dispatcher" ADDITIONAL_LOAD_PATHS.reverse.each { |dir| $:.unshift(dir) if File.directory?(dir) } if defined?(Apache::RubyRun) Dispatcher.dispatch
if you forgot how to use nano already…
$nano -w dispatch.rb
now save and exit nano
- set the necessary permissions in ‘public’
$chmod 755 *
Setting up your dreamhost site
- enable FastCGI (see screenshot)
- append ‘/public/raboof’ to your default “root site directory” (see screenshot)
so instead of web root: /home/username/website.com/
use web root: /home/username/website.com/public/raboof
![photo]
Fin
exit your ssh session by typing ‘exit’
that’s it, now enjoy ruby secksyness powered by dreamhost… comments and suggestions to improve this guide are welcome. gl hf.





August 3rd, 2008 at 02:34 AM
I ALWAYS have trouble installing Rails on my dreamhost accounts - you are a saviour
your tutorial will save me a lot of hassle
thanks!