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.

Leave a comment

Your email address will not be published.