Capistrano recipe and howto for Rails, Mongrel, and Nginx
UPDATE: This is outdated due to the release of Capistrano 2… I will work on a new tutorial as soon as I have a project I need to deploy… 1-10-08
All righty then. Recently my firm (SabreTech) got a contract to write and deploy a fairly complicated web app for a local business. Immediately I asked my friend Xian to give me some deployment ideas, and he suggested I use nginx as my web server instead of Apache as well as Slicehost as my vps host provider…
So I set up my Slicehost account and started hacking. About a week later (five hours of work snuck in here and there), I’ve got my vps up and running smoothly. I’ve been using Capistrano for deployment for awhile, but I also wanted to use it to set up my server, and that is when I ran across deprec. Deprec is a nice little gem with a ton of capistrano recipes for setting up and deploying a server. It had some great recipes for deploying to Ubuntu, so I chose Ubuntu as my OS for my new slice (vps).
Now I just had to write some of my own recipes for setting up and deploying with Nginx instead of Apache. That is where most of my time was spent. Below you’ll find my instructions and recipes:
Prerequisites
- Install the capistrano and deprec gems on your development machine
- Cap your app; in the root of your app dir, run:
cap -A
- Set up deprec: from the root of your app, run
deprec_dotfiles
which just creates a file in your user dir called.caprc
, which contains the following line:
require 'deprec/recipes'
- Your server must be running ubuntu (it should work on any debian based OS though)
- Your svn repository must be accessible by the same user listed in your
deploy.rb
nginx.conf
,database.yml.production
, anddeploy.rb
must exist and be configured inapp/config
(and checked into your repository)- You need to take this file and append the contents to the bottom of your
config/deploy.rb
(these are the recipes I wrote) - Make sure and configure the mongrel settings in your
deploy.rb
Instructions
- Log into your server as root and add a new user (the user you specify in your
deploy.rb
), set the password, and finally add to sudoers fileuseradd -m bobby
passwd bobby
visudo
- From the root of your app run:
cap install_rails_stack_with_nginx
- The last one takes a while, but when it is done run:
cap svn_cache_credentials
- Finally run:
cap deploy_first_time
- (When it asks for mysql user password just press enter, unless you changed the mysql root password)