Deploying Rack Apps on Dreamhost via Passenger (including Sinatra)
I don’t like deployment via FastCGI that much. It’s just too unstable, and random for my tastes. So when I saw that Passenger was going to support Rack, I knew I had to get that working on Dreamhost.
Once I started going at it, it only took me a few minutes to make everything work. You can find documentation at the Passenger Github repository.
Steps:
- Setup your account to support mod_rails
- Create the directory structure
- Make a rackup file (config.ru)
- Create a very simple Sinatra application
1) Setting up the account
- Domains -> Manage Domains -> Edit (web hosting column)
- Enable “Ruby on Rails Passenger (mod_rails)”
- Add the public directory to the web directory box. So if you were using “gittr.com”, it would change to “gittr.com/public”
- Save your changes
2) Creating the directory structure
domain.com/ domain.com/tmp domain.com/public # a vendored version of sinatra - not necessary if you use the gem domain.com/sinatra
3) Creating a rackup file
# This file goes in domain.com/config.ru require 'sinatra/lib/sinatra.rb' require 'rubygems' Sinatra::Application.default_options.merge!( :run => false, :env => :production ) require 'test.rb' run Sinatra.application
4) A very simple Sinatra application
# this is test.rb referred to above get '/' do "Worked on dreamhost" end get '/foo/:bar' do "You asked for foo/#{params[:bar]}" end
And that’s all there is to it! Once it’s all setup, point your browser at your domain, and you should see a “Worked on Dreamhost” page. To restart the application after making changes, you need to run “touch tmp/restart.txt”.
June 21st, 2008 at 5:35 am
where does the app logs?
is possibly to define a RackEnv development
on dreamhost? bye
June 24th, 2008 at 1:31 pm
Yes the app logs, is there some agreed upon standard/assumption. So far I haven’t found a single Sinatra example (including the deployment ones), mention about the log file.
June 24th, 2008 at 2:42 pm
It’s a good question. Sinatra uses Rack’s CommonLogger middleware to do request logging. But beyond that I have no idea how logs work in Sinatra. I’ll look it up, and write up a post on it.
June 24th, 2008 at 3:11 pm
[…] of this this blog I suspect would be the one which talks (in nice, easy-to-understand terms) about how to deploy Rack-based applications to Dreamhost using their new Passenger support. SHARETHIS.addEntry({ title: “Deploying Rack Applications to […]
July 4th, 2008 at 12:13 pm
[…] awesome!) and thought I’d deploy something to my mess-around DreamHost account. I followed these instructions which totally worked and was so easy. But when it came time to actually deploy my real app with […]
October 9th, 2008 at 11:24 pm
[…] be able to deploy this new app to my Dreamhost account. A quick search turned up a useful post with information on deploying to Sinatra apps on Dreamhost. Unfortunately, the first attempt didn’t […]
November 10th, 2008 at 12:02 am
HI,
I’m trying to deploy a new rack framework and following all your steps: the config.ru is loaded after I fixed the requires but hitting my domain only display a totally empty page, it seems is showing the /public folder since I can see the /images folder but is not running the rack app, any ideas, is the public folder supposed to have a symlink or magic file? I have all the tmp/ folder also and I restarted the passenger but nothing, blank page again.
Thanks, Peter.
November 15th, 2008 at 8:22 am
worked fine, thanks!
February 21st, 2009 at 5:08 pm
I’m using dreamhost. I’ve installed Sinatra-0.9.0.4 locally in ~/.gems dir but am getting the dreaded
“can’t activate rack (>= 0.9.1, runtime), already activated rack-0.4.0”
and then if I uninstall rack (yeah, I know, not a good idea) I get “RubyGem version error: rack(0.3.0 not >= 0.9.1)” - which makes some sense due to the sinatra version I’ve installed but its a bit odd that it now complains about 0.3.0 instead of 0.4.0.
I can try down-revving sinatra to a version that will work with rack 0.3.0 but it seems like the wrong direction. Any suggestions?
March 7th, 2009 at 8:43 pm
@JohnB, did you ever find a solution to your problem? I’m running into the same dreaded “can’t activate rack (>= 0.9.1, < 1.0, runtime), already activated rack-0.4.0”, and am at an impasse.
If you did, and if you happen to come back to read this blog :), could you shoot me an email?
March 8th, 2009 at 12:02 am
[…] is a lot of good information on how to run Sinatra on Dreamhost, but after following all the excellent advice, I […]
March 8th, 2009 at 12:06 am
Turned out the “can’t activate rack (>= 0.9.1, < 1.0, runtime), already activated rack-0.4.0” problem was pretty easy to get around.
See my blog post about it here : http://blog.yetisoftware.com/2009/03/07/sinatra-on-dreamhost/