Original Resource (in Russian): http://yiiframework.ru/forum/viewtopic.php?t=22253
Important: Server SSH-Key must be made without passphrase!
You could have passphrase, then you'll need to use ssh-agent to store & run the passphrase.
mkdir /var/www/.ssh
chown -R apache.apache /var/www/.ssh
sudo -u apache ssh-keygen -t rsa -C "[email protected]"
Register new public key (apache public key) to Gitlab
Make sure .git/FETCH_HEAD
is owned and group for apache
apache apache 91 Nov 25 09:40 FETCH_HEAD
In /etc/sudoer
apache ALL = NOPASSWD: /usr/bin/git
test as apache to pull:
sudo -u apache git pull
Add hook.sh
#!/bin/bash
now=`date`
printf "\n\nHook started at $now"
echo '---------------------------------------'
echo `
SECONDS=0 &&
git fetch --all &&
git reset --hard origin/master &&
git pull origin master &&
php yii migrate/up --interactive=0 &&
php init --env=Production --overwrite=All &&
chmod +x yii
`
printf "Hook completed after ${SECONDS} seconds\n"
Hi how to use it?