Deploying with Github

Just a note for myself. Or if anyone’s interested, feel free to continue reading.

This posts records the steps needed to allow the webserver to run a “git pull” command in your website’s folder.

Setting up SSH

In the case of Nginx, the home folder is /var/cache/nginx/

You need a .ssh folder here with the ownership given to “nginx”, which is the user account the webserver runs as.

Generate your PKI keys, update the public key at github and also make sure nginx owns those keys.

Website folder permissions

You will need to change the ownership of all the files in your web folder, including the .git folder and files to the “nginx” user account.

Git pull

su nginx to “log in” as the nginx user. You may need to change the bash settings in /etc/passwd in order to allow this login.

go to your website folder and run “git pull”. You will be asked to add the public key for into your list of known hosts, so just type in “yes”

Github hook

I have a php file in /var/www/html that runs the git pull in the website folder when accessed.

The line of code is simply:

shell_exec(“cd /var/www/; git pull”);

Then add the url to this file in github’s hooks section and whenever you push to github, github will send a post to this file, triggering the git pull in that website folder.