Publish yii webapp using Git push

You are viewing revision #1 of this wiki article.
This version may not be up to date with the latest version.
You may want to view the differences to the latest version.

next (#2) »

  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 instruction, I read it somewhere and re-organize it 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, PLEASE donwload 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 the instruction 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 happends)

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 follwoing 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 proudction master

enjoy!