home / blog

Rails 4.0.0 with Ruby 2.0 on a Dreamhost shared server

Build ruby from source. RVM won’t work out of the box because it tries to use sudo. It’s quite easy.

mkdir build
cd build


tar xzf ruby-2.0.0-p247.tar.gz
cd ruby-2.0.0-p247
 ./configure --prefix /home/adamish/ruby   # <=== make sure you install to your own home directory
make install

Make your custom ruby default. Add the following to your ~/.bash_profile

export GEM_HOME="$HOME/.gems"
export PATH=~/ruby/bin:$PATH

Install rails

gem install rails --no-document

Create dummy site for testing

rails new HorseApp
mv HorseApp/* . # move to top level

Add following lines to Gemfile

# required for JS runtime
gem 'therubyracer'
# required for FCGI wrapper
gem 'fcgi'

Install the new gems

bundle install

Create FCGI wrapper script – public/dispatch.fcgi


ENV['RAILS_ENV'] = 'development'
ENV['HOME'] ||= `echo ~`.strip
ENV['GEM_HOME'] = File.expand_path('~/.gems')
ENV['GEM_PATH'] = File.expand_path('~/.gems')

require 'fcgi' 
require File.join(File.dirname(__FILE__), '../config/environment.rb')

class Rack::PathInfoRewriter
  def initialize(app)
    @app = app
  def call(env)
    parts = env['REQUEST_URI'].split('?')
    env['PATH_INFO'] = parts[0]
    env['QUERY_STRING'] = parts[1].to_s
Rack::Handler::FastCGI.run  Rack::PathInfoRewriter.new(HorseApp::Application) 

Add following to .htaccess

<IfModule mod_fastcgi.c>
AddHandler fastcgi-script .fcgi
<IfModule mod_fcgid.c>
AddHandler fcgid-script .fcgi

Options +FollowSymLinks +ExecCGI 

RewriteEngine On 

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ public/dispatch.fcgi/$1 [QSA,L] 
ErrorDocument 500 "Rails application failed to start properly"

Try it out! You should see the standard “Welcome aboard – You’re riding Ruby on Rails!” development starter page.

This entry was posted in geek and tagged , . Bookmark the permalink.

2 Responses to Rails 4.0.0 with Ruby 2.0 on a Dreamhost shared server

  1. rafaeldx7 says:

    I need to change this

    RewriteRule ^(.*)$ public/dispatch.fcgi/$1 [QSA,L]

    for that

    RewriteRule ^(.*)$ dispatch.fcgi/$1 [QSA,L]

    to work

  2. Devin says:

    I stumbled across your site trying to do pretty much this very same thing, and it almost works for me. I can install ruby and rails just fine, but then when I try to create a test app, I keep getting a 500 error and my error log tells me I’ve exceeded the maximum number of redirects, 10. I’m new to this and I’m not exactly sure what’s going on, I pretty much just copied your code, changed it to my username, stuck the dispatch.fcgi in my public folder and my .htaccess in my home folder, but I can’t get it to work. Any ideas?

Leave a Reply

Your email address will not be published.

− 1 = six

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>