View this site in English Ver este site em português

Deploying (the latest) Sinatra apps on Dreamhost

Today I decided that would run my Sinatra app on Dreamhost. Until today I had only run the app on localhost, via shotgun. After trying to deploy it on heroku, without success, I remembered I had a shared account at dreamhost and then, why not?

Ok, after some failures (no single tutorial worked) I finally managed to make it run. Assuming you already have a sinatra app working and configured it using bundler, here are the steps that worked for me:

$ mkdir ~/.gems $ mkdir ~/bin $ mkdir ~/lib
$ mkdir ~/src
$ cd ~/src
$ wget http://production.cf.rubygems.org/rubygems/rubygems-1.8.7.tg
$ tar zxvf rubygems-1.8.7.tgz
$ cd rubygems-1.8.7 $ ruby setup.rb --prefix=$HOME

Then, added to my ~/.bash_profile:

export GEM_HOME="$HOME/.gem"
export GEM_PATH="$GEM_HOME"
export RUBYLIB="$HOME/lib:$RUBYLIB"
export PATH="$HOME/bin:$HOME/.gem/bin:$HOME/.gem/ruby/1.8/bin:
$HOME/usr/local/bin:$HOME/usr/bin:$PATH"

and then, back again to bash:

$ source ~/.bash_profile
$ gem install bundler
$ cd path_to_your_app
 Important! Your rack version must be “1.2.1″, so in your Gemfile you should have:
gem "rack", '1.2.1'

Now you can build you gems:

$ bundle install

Finally, your config.ru should also contain the following lines:

Gem.clear_paths
ENV['GEM_HOME'] = '/home/your_user/.gem'
ENV['GEM_PATH'] = '/home/your_user/.gem:/usr/lib/ruby/gems/1.8'
require 'rubygems'
require 'bundler'
Bundler.require
FileUtils.mkdir_p 'log' unless File.exists?('log')
log = File.new("log/sinatra.log", "a")
$stdout.reopen(log)
$stderr.reopen(log) disable :run, :reload
set :environment, :production
set :views, File.dirname(__FILE__) + '/views'
require 'app'
run Sinatra::Application
 And that’s it! I’m running the latest version of Sinatra (which today is 1.2.6) without problems \o/

If you run into problems, the two posts which helped me most were the following two:

Using Bundler for Sinatra Applications On A Shared Host

and

Sinatra on Dreamhost

Leave Comment