How to Deploy Rails 2 with Git/Capistrano on Mongrel at Hostgator

October 12th, 2011 by Regaz

This tutorial has been executed on Hostgator hosting with Rails 2.1.14 on Apache and CGI Mongrel.

Local Prerequisites:
Git
Ssh Access to Remote Server

Local:

cd yourRailsApp
gem install capistrano
cd ..
zip -r yourRailsApp.zip yourRailsApp

We will clone back the app from server so to keep a copy:

mv yourRailsApp yourRailsApp.backup

Remote:

cd ~
mkdir git

Local:

scp -P yourSSHPort yourRailsApp.zip yourUsername@yourDomain:~/git

Remote:

cd ~/git
unzip yourRailsApp.zip
cd yourRailsApp

Now you should setup your .gitignore file.

pico .gitignore

A default .gitignore content:

.DS_Store
log/*.log
tmp/**/*
db/*.sqlite3

Now you turn the ~git directory into a git repository

git init
git add .
git commit -am "Initial commit"

After we proceed to Setup Capistrano locally
Local:

git clone ssh://yourUsername@yourDomain:yourSSHPort/git/yourRailsApp 
path/To/yourRailsApp
cd path/To/yourRailsApp
capify .

Now your need to Configure Capistrano to use the git repository. Here are my working settings.

set :application, "yourRailsApp"
set :user, "yourUserName"
set :domain, "yourDomain"
set :port, yourSSHPort
set :repository, "ssh://#{user}@#{domain}:#{port}/home/#{user}/git/#{application}"

set :scm, :git

set :scm_username, user
set :runner, user
set :use_sudo, false
set :branch, "master"
set :deploy_via, :remote_cache
set :git_shallow_clone, 1
set :rake, "/home/yourUserName/ruby/gems/gems/rake-0.9.2/lib/rake.rb"
set :ssh_options, {:forward_agent => true}

set :deploy_to, "/home/#{user}/rails_apps/#{application}"

default_run_options[:pty] = true

role :web, domain
role :app, domain
role :db, domain, :primary => true

Remote:
To begin the Git rollover (There are others procedures buts this is a working one:)

git config receive.denyCurrentBranch ignore

Local:

git add .
git commit -am "Capified"
git push

Remote:
To achieve the Git rollover

git checkout -f

Now you should be able to Deploy your up by Capistrano
Remote:

cap deploy:setup
cap deploy:cold

After the process is Achieved you will find your deployed App on your Server at:
~/home/yourUserName/rails_apps/yourRailsApp/Current
The last five Versions are on:
~/home/yourUserName/rails_apps/yourRailsApp/Releases

Now to Start your Application:

cd ~/home/yourUserName/rails_apps/yourRailsApp/Current
script/server

The Basic Usage of git and capistrano to Deploy every New Version of your App is:

git add .
git commit -am "New Version Comments"
git push
cap deploy

Check this…


Bloogger Blogger, Google Blogger, Google Google

Feel Better on Apache

Tags: , , , , , ,