Deploying rails app with mod_rails on dreamhost
By NickJust 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.
- In the dreamhost control panel, enable the “Ruby on Rails Passenger (mod_rails)?” checkbox.
- Specify your web directory as : /home/username/yourdomain.com/yourapp/current/public/
- 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.
- 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.
- I have a svn user with same credentials as the ssh user, which makes capistrano play nice.
- Create your database plus user via dreamhost’s panel
- Make sure to update production.yml with these settings
- Capify your application via capify . on your local working copy
- 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
- cap deploy:setup
- cap deploy:cold
- 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