Publish yii webapp using Git push

  1. Warning
  2. [on server] - install git, nothing fancy just basic
  3. [on local] - prepare git repository
  4. [on server] - secure your data on server
  5. [on server] - git hook (top secret)
  6. [on local] - prepare for git push
  7. [on local] - ta-ta, push to publish

Warning

I did not invent this instructions, I read it somewhere and re-organized in my way as I was trying and it works for me;

Assuming server is Ubuntu Linux;

If you have dynamic files uploaded by user or sqlite as database, PLEASE download them first before you git push to publish, if you lose them by using this instruction, don't come back to blame on me!

I am not an expert on git nor in server security, use this instructions at your own risk;

[on server] - install git, nothing fancy just basic

sudo apt-get install git-core

[on local] - prepare git repository

git init / add / commit
+--app-root
   |
   +--.git
   |
   +--private
   |  |
   +  +--.htaccess
   |  |
   +  +--resource (whatever used at design time)
   |
   +--public
      |
      +--yii-app (pure & clean)

[on server] - secure your data on server

never point your web route to your private content!!

so in apache conf file

DocumentRoot "/var/www/app-root/public"

under "/var/www/app-root/private" create file .htaccess (double secure in case accident happens)

order deny, allow
deny from all

[on server] - git hook (top secret)

modify /var/www/app-root/.git/hooks/post-receive and give it execute permission

#!/bin/sh
cd ..
GIT_DIR='.git'
umask 002 && git reset --hard

## you don't need those two lines if you are not using sqlite
chmod -R 777 public/protected/data
chmod -R 777 public/protected/data/*

give it execute permission

chmod +x hooks/post-receive

[on local] - prepare for git push

modify or add the following content to /app-root/.git/config

[remote "production"]
	fetch = +refs/heads/*:refs/remotes/production/*
	url = ssh://root@yourwebserver~/var/www/app-root/
[branch "master"]
	remote = production
	merge = refs/heads/master

[on local] - ta-ta, push to publish

under /app-root/ folder:

git push production master

enjoy!