Deploying rails app with mod_rails on dreamhost

By Nick

Just finished deploying a rails application on dreamhost. I used the mod_rails option dreamhost provides and it turned out to work very easy.

These were the steps I took to get it working.

  1. In the dreamhost control panel, enable the “Ruby on Rails Passenger (mod_rails)?” checkbox.
  2. Specify your web directory as : /home/username/yourdomain.com/yourapp/current/public/
  3. Gotcha:Dreamhost will automatically create this directory. If you are going to use capistrano for deployment, delete the /home/username/yourdomain.com/yourapp/current directory and it’s subdirectory. Capistrano will set these up for you via symlinks and will fail if there already are directories. Took me an hour to figure that out.
  4. I have my svn repository also hosted on dreamhost, on a svn.mydomain.com subdomain, layout of my svn repo is dev.mydomain.com/myapp/trunk. My rails app’s source code lives there.
  5. I have a svn user with same credentials as the ssh user, which makes capistrano play nice.
  6. Create your database plus user via dreamhost’s panel
  7. Make sure to update production.yml with these settings
  8. Capify your application via capify . on your local working copy
  9. Adapt deploy.rb to look like this:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    
    set :application, "myapp"
    set :domain, "mydomain.com"
    set :user, "username"
    set :password, "passwd"
    set :repository,  "http://dev.mydomain/#{application}/trunk/"
     
     
    set :deploy_to, "/home/#{user}/#{domain}/#{application}"
     
     
    role :app, domain
    role :web, domain
    role :db,  domain, :primary => true
     
    namespace :deploy do
      desc "Restarting mod_rails with restart.txt"
      task :restart, :roles => :app, :except => { :no_release => true } do
        run "touch #{current_path}/tmp/restart.txt"
      end
     
      [:start, :stop].each do |t|
        desc "#{t} task is a no-op with mod_rails"
        task t, :roles => :app do ; end
      end
    end
  10. cap deploy:setup
  11. cap deploy:cold
  12. You now should have a running rails app. Subsequent deploys work via cap deploy.

One last note: if you use google apps for your dreamhost mail,and you want your application to send email through that gmail account you need to do something special in your rails app. I highly recommend you have a look at Preston Lee’s blog post for help.

Hope this helps.

Share This

Leave a Reply


Close
E-mail It
Socialized through Gregarious 42