This is the script @oxyguy3 wrote to deploy all commits to the master branch on GitHub onto his shared hosting cPanel server for his site. Unlike the original script I forked off, I could run shell_exec on my host so removed all the SSH stuff.
I also took care to validate the secret that GitHub passes along to prevent anyone else from activating the webhook. This is something I notice a lot of the other variations of this script I've found via googling neglect to do, but it seems like a good idea so I went for it.
First, you need to put deploy.php on your server, somewhere where it's accessible to the public (I've only tested putting it right at
/public_html/deploy.php, but I can't think of any reason you couldn't rename it or put it in a subdirectory). At the top of the script is a series of
define() statements -- you will need to change most of these to suit your setup (they all have comments describing what they do).
You'll need to create a webhook in the settings for your repo on GitHub. Set the Payload URL to the URL of this script (i.e. "http://example.com/deploy.php"), set the Content type to "application/json", and set the Secret to the same string of random characters that you set GITHUB_SECRET to in deploy.php. Check the radio box for "Just the push event" and then save the webhook.
You also need to have already cloned your repository into
~/public_html on the cPanel server. You can do this by manually SSHing in to the server from your local machine and running the
git clone command.
I think that covers it all? Tweet me @anthc if you have any issues.