This gist assumes:
- you have a local git repo
- you have an online remote repository (github)
- you have a server running Apache with git already installed
you should be able to do the same with Java, Perl, RoR, JSP etc. however you'll need to recreate the (rather simple) PHP script
Here we add the deployment script and push it to the origin, the deployment script runs git commands to PULL from the origin thus updating your server
See deploy.php
git add deploy.php
git commit -m 'Added the git deployment script'
git push -u origin master
- https://github.com/oodavid/server.com/settings/hooks
- Select Add webhook
- Enter the URL to your deployment script - http://server.com/deploy.php into Payload URL
- Generate a highly random string for the Secret
- You can keep the default for events that trigger the webhook (push event) or you can customize it yourself
- Click Add webhook
Here we clone the origin repo into a chmodded /var/www/html folder, you can change the path to your own path
git clone [email protected]:you/server.git /var/www/html
You need to check that the permission for your deployment script is correct (644)
Now you're ready to go :-)
- It would be trivial to setup another repo on your server for different branches (develop, release-candidate etc) - repeat most of the steps but checkout a branch after pulling the repo down
- If you came from the fork you would notice that much had been removed and you will no longer be able to trigger deployment manually. This is changed to fit with github's recommended way of setting up webhooks but with php.
- You will need to store the random key generated above in your .htaccess file as an environment variable.
- Never hard code the random key into the code
- You will not need to add the SSH key to github, that is not neccessary.
- See Webhooks for more details.