Dreamhost just rolled out Passenger / mod_rails — a simplified way to run Rails apps on Dreamhost shared servers. Here are my notes on setting up a nice Dreamhost environment for your Rails app. I use a separate user for each Rails app. My apps run pretty well. They are not fast to boot up, but once running, they are reasonably snappy - I don’t host any high traffic sites on my shared domains.
One lovely thing about mod_rails - when your app is screwed up and won’t boot, you get a helpful error screen with a Rails stack trace. Huge.
Domain and DB setup
Create your domain in the Dreamhost web panel.
- Create a new user specifically for the domain you’re adding. Be sure to allow terminal/SSH access.
- Create the MYSQL database
- Create the domain, using the new user you created, and specifying Ruby on Rails Passenger (MOD_RAILS) option.
For late-breaking info on Passenger on Dreamhost, see the wiki page:
http://wiki.dreamhost.com/Passenger
Set up SSH keys
This is so you don’t have to type your password every time you SSH into the server. You should already have an SSH key created on your dev machine – if you don’t know how to do that, google “ssh-keygen”.
ssh username@yourdomain.com 'test -d .ssh || mkdir -m 0700 .ssh ; cat >> .ssh/authorized_keys && chmod 0600 .ssh/*' < ~/.ssh/id_dsa.pub
You’ll have to enter your password when you run this. Next time you SSH in, you won’t.
Set up a local set of gems
I do this to shield my app from any updates that Dreamhost may roll out.
Create the necessary paths in your .bash_profile:
mkdir .gems echo 'export GEM_HOME="$HOME/.gems"' >> .bash_profile echo 'export GEM_PATH="$GEM_HOME:/usr/lib/ruby/gems/1.8"' >> .bash_profile echo 'export PATH="$HOME/.gems/bin:$PATH"' >> .bash_profile source .bash_profile
Verify your gem setup, and update gems to their new location
gem env
Note the gem path from the above command and reference it in the next command:
rm -f /PATH/TO/GEM/PATH/FROM/ABOVE/source_cache
Then,
gem update
This one will take a while.
Switch to your locally installed gems
Now, go back and edit your .bashprofile and change the GEMPATH export as follows – you’re removing the Dreamhost gem libraries from your gem path:
export GEM_PATH="$GEM_HOME"
Exit vim and:
source .bash_profile
Install Rails
Now check what you got:
gem list
Verify that all the gems you need are there. For some reason the Rails gems don’t automatically install. So:
gem install rails
Configure your Rails environment
- database.yml
- environment.rb : comment in the ENV[‘RAILS_ENV’] = ‘production’
Create a restart file
If your app doesn’t already have a RAILS_ROOT/tmp folder, create one.
Add a restart.txt file in that RAILS_ROOT/tmp folder. To restart your app, do:
touch tmp/restart.txt
There used to be all kinds of nonsense involving dispatch.fcgi revisions, etc. but that seems to be over now. Praise be.