Skip to content

Instantly share code, notes, and snippets.

Last active May 1, 2016 16:49
Show Gist options
  • Star 21 You must be signed in to star a gist
  • Fork 9 You must be signed in to fork a gist
  • Save MicahChalmer/4316253 to your computer and use it in GitHub Desktop.
Save MicahChalmer/4316253 to your computer and use it in GitHub Desktop.
Scripts to set up Ruby 1.9.3 on a DreamHost shared hosting account via rbenv and ruby-build, and run a Rack app with it via FastCGI.
<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 ^(.*)$ dispatch.fcgi/$1 [QSA,L]
this_dir=`dirname $0`
unset GEM_HOME
unset GEM_PATH
export PATH=~/.rbenv/bin:"$PATH"
eval "$(~/.rbenv/bin/rbenv init -)"
exec ~/.rbenv/shims/ruby "${this_dir}/dispatch_fcgi.rb" "$@" 2>>"${err_log_file}"
require 'rubygems'
require 'bundler'
Bundler.setup(:default, :fcgi)
require 'rack'
class Rack::PathInfoRewriter
def initialize(app)
@app = app
def call(env)
env['SCRIPT_NAME'] = '' # Don't delete it--Rack::URLMap assumes it is not nil
pathInfo, query = env['REQUEST_URI'].split('?', 2)
env['PATH_INFO'] = pathInfo
env['QUERY_STRING'] = query
app, options = Rack::Builder.parse_file('')
wrappedApp = do
use Rack::ShowExceptions
use Rack::PathInfoRewriter
run app
end wrappedApp
# Initial setup for Ruby 1.9.3 on DreamHost shared hosting.
# We assume you're already in your project's root directory, which should
# also be the directory configured as "web directory" for your domain
# in the DreamHost panel.
# Install rbenv and ruby-build
git clone git:// ~/.rbenv
git clone git:// ~/.rbenv/plugins/ruby-build
# Create temporary directory--DreamHost does not allow files in /tmp to be
# executed, which makes the default not work
mkdir ~/.rbenv/BUILD_TEMP
# DreamHost will set your GEM_HOME and GEM_PATH for you, but this conflicts
# with rbenv, so we unset them here. You'll want to do this in your .bashrc
# on the dreamhost account.
unset GEM_HOME
unset GEM_PATH
# Add rbenv to PATH and let it set itself up.
# You probably want these two lines in your .bashrc as well:
export PATH=~/.rbenv/bin:"$PATH"
eval "$(~/.rbenv/bin/rbenv init -)"
# Decide which version of Ruby we're going to install and use.
# Using that as the temp space, build and install ruby 1.9.3.
# The MAKE_OPTS=-j2 part is to limit make to 2 simultaneous jobs,
# so that DreamHost won't kill the build of ruby.
# Now everything is set up properly, you should be able to set your
# directory to use the new ruby:
rbenv local $NEW_RUBY_VERSION
# Bundler isn't included with ruby, so install it first:
gem install bundler
# Make sure rbenv picks up the newly installed bundler:
rbenv rehash
# Then use it to install the rest of your gems:
bundle install
# Create the "log" dir in for the file containing the stderr of your dispatch.fcgi script:
mkdir -p log
Copy link

muescha commented Oct 25, 2014

thx for the code examples

here is the blog article for this gist:

Copy link

I'm lost where to put line 27 in help!

Copy link

Thanks for this, it's certainly saved me some tedious time and is likely a much better solution than I would've hacked together :)

Copy link

@jrlewis889 prob late, but maybe help someone else... NEW_RUBY_VERSION is just a temporary variable to use during the install. You paste it into your terminal and hit then continue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment