Skip to content

Instantly share code, notes, and snippets.

@danielhickman
Last active August 29, 2015 14:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielhickman/c193f52a76a5df143db3 to your computer and use it in GitHub Desktop.
Save danielhickman/c193f52a76a5df143db3 to your computer and use it in GitHub Desktop.
How to Create a Simple GitHub Webhook Deployment

Dependencies:

  • #linuxmasterrace
  • git
  • php
  • apache

Commands to run before:

cd /var/www/example.com/
git clone https://github.com/username/reponame.git
mv reponame public_html
chmod 755 -R public_html/
chown www-data:www-data -R public_html/

PHP:

<?php
echo shell_exec("cd /var/www/example.com/public_html/ && git fetch --all && git reset --hard origin/master && git pull")
?>

GitHub Webhook Setup:

Note:

  • This will be able to be triggered by anyone at the URL by just navigating to it. Add an if statement looking for a payload from GitHub or a secret to prevent that if needed
  • Replace username with your GitHub username, reponame with your name of your repo, example.com with the domain of your website, and /var/www/example.com/ with the directory of your server root.
@crutchcorn
Copy link

I love the fact that you did #linuxmasterrace. NEVER change that. xD

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment