在LAMP環境下使用Capistrano進行佈署

在LAMP環境下要進行佈署,Capistrano或許是個不錯的選擇,如果你不能用一行
指令就完成佈署,就代表一定有什麼地方出了問題….以下是步驟:

sudo apt-get install rubygems
gem install capistrano

cd /path/to/app  #到你要deploy的目錄下,通常是個repo
mkdir config
capify .
會產生兩個檔案: Capfile 、 config/deploy.rb

之後進入deploy.rb修改一些內容

set :user, ""  #要以那個user執行這件事
set :application, "" #你的application name,通常用來執行放到不同的目的地
set :repository, "" #你的repo

set :use_sudo, false  #是否使用sudo ,通常不需要
set :scm, :git #以哪種方式執行,這裡選git
# set :scm, :git # You can set :scm explicitly or Capistrano will make an intelligent guess based on known version control directory names
# Or: `accurev`, `bzr`, `cvs`, `darcs`, `git`, `mercurial`, `perforce`, `subversion` or `none`

#role :web, "your web-server here" # Your HTTP server, Apache/etc
#role :app, "your app-server here" # This may be the same as your `Web` server
#role :db, "your primary db-server here", :primary => true # This is where Rails migrations will run
#role :db, "your slave db-server here"

# if you want to clean up old releases on each deploy uncomment this:
# after "deploy:restart", "deploy:cleanup"

# if you're still using the script/reaper helper you will need
# these http://github.com/rails/irs_process_scripts

# If you are using Passenger mod_rails uncomment this:
# namespace :deploy do
# task :start do ; end
# task :stop do ; end
# task :restart, :roles => :app, :except => { :no_release => true } do
# run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
# end
# endi
role :web, "xxx.xxx.xxx.xxx"  #要deploy到哪台主機 
set :deploy_to, "/srv/production/"  #要deploy到哪個目錄

以上只是個簡單的範例,你可以自己修改成你要的deploy 方式,之後打:

cap deploy

完成!!

參考文章:
http://teachmetocode.com/articles/deployment-with-capistrano/
http://mathew-davies.co.uk/2009/10/28/php-deployment.html
https://github.com/capistrano/capistrano/wiki/2.x-from-the-beginning
http://hivelogic.com/articles/deploying-expressionengine-github-capistrano
https://github.com/capistrano/capistrano/wiki