Set up SSH Access
There are 2 versions for SSH keys, Protocol V1 and V2
SSH V1:
Create a key on you dev machine like so:
$ ssh-keygen -t rsa
then UPLOAD that public key to your server using scp, make sure you upload it as a new file called authorized_keys
$ scp .ssh/id_rsa.pub deploy@myserver.com:~/.ssh/authorized_keys
SSH V2:
$ ssh-keygen -t dsa
if you like you can set a passphrase, or just leave it empty
repeat the passphrase or leave it blank
$ scp .ssh/id_dsa.pub deploy@myserver.com:~/.ssh/authorized_keys2
SSH to your server, and Make sure the files are not readable for other users/groups. chmod 600 authorized_keys* does the trick.
Configuring Capistrano
First we want to capify our project so just type capify .
Capistrano will place a config file in the config directory called deploy.rb
set :application, "project_name"
server “myserver.com”, :app, :web, :db, :primary => true
set :user, “deploy”
set :deploy_to, “/var/www/apps/#{application}”
set :deploy_via, :remote_cache
set :mongrel_conf, “#{deploy_to}/current/config/mongrel_cluster.yml”
set :runner, nil
set :scm, :git
set :repository,”myserver.com:/var/www/git_repo/#{application}”
set :branch, “master”
namespace :deploy do
task :symlink_shared do
run “ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml”
run “ln -nfs #{shared_path}/config/mongrel_cluster.yml #{release_path}/config/mongrel_cluster.yml”
end
task :restart do
run “cd #{current_path} && sudo mongrel_rails restart”
end
end
set :copy_compression, :bz2
after ‘deploy:update_code’, ‘deploy:symlink_shared’
We need to turn on the :pty option because it would seem we don’t get the passphrase prompt (if we set it up on the first step)
If you’re using your own private keys for git you might want to tell Capistrano to use agent forwarding with this command
ssh_options[:forward_agent] = trueset :deploy_via, :remote_cacheRemote caching will keep a local git repo on the server you're deploying to and simply run a fetch from that
rather than an entire clone. This is probably the best option and will only fetch the differences each deploy*You may have to add your server to your known hosts file