使用 git 部署代碼到服務器
在小站點上,直接用git來部署php代碼相當方便,你的遠程站點以及本地版本庫都有一個版本控制,追蹤問題或者回滾是很輕松的事情。下面介紹用git部署時的設置步驟
在遠程服務器的設置
假定你需要部署的代碼在/var/www/yoursite
cd /var/www/yoursite git init .git config receive.denyCurrentBranch ignore git config --bool receive.denyNonFastForwards falsecd .git/hooks wget https://gist.githubusercontent.com/volca/9482044/raw/344a590af350b997db3819fa21426dfe8bc140f4/post-updatechmod +x post-update
在本地git庫中新增配置
[remote "prod"] url = your-ssh-username@your-host:/var/www/yoursite/
注意: remote 必須為 prod,因為當我們 push 代碼到 remote repository 時,通過 git 的 post-receive hooks。執行
git checkout prod -f
這樣就算設置完成了。
如果你想把本地的代碼推送到遠程服務器,下面簡單的步驟就可以做到
git pull git push prod
注意事項
如果遠程服務器上git的配置目錄.git暴露在外部可訪問的位置,請在web服務器上設置這個目錄不可見。
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!