Here is a very simple way to add automatic deployment via GitHub. This assumes
- You have shell access to your web host
- Your website is in a repository on GitHub
- CGI scripts are enabled for your website
- That git (and optionally composer if you use that) is installed
Log on to your web host and do the initial pull.
$ git clone https://github.com/<you>/<website>.git .
Put the following script in a file named for example
deploy.cgi in your website root.
echo Content-type: text/plain
Add execute rights to the script.
You should now be able to visit
http://<your-website>/deploy.cgi in your browser and see output like this:
Loading composer repositories with package information
Installing dependencies from lock file
Nothing to install or update
Generating autoload files
Set up GitHub service hook
https://github.com/<you>/<website>/settings/hooks, click on WebHook URLs and enter the full URL to your script,
Test it out
With this set up you should be able to make a change at your dev machine, commit it and push it to GitHub. The script should then be executed shortly after and your website should be updated automatically. Pretty cool
This is of course ultra simple, and if this is a critical site you should probably add some security of some sort. A simple version could be to use a cryptic name like a guid for the script and of course not have this script checked in at GitHub. You might also perhaps want to only pull from a certain branch or things like that, but for a small simple site this works pretty well as long as you remember to only push to GitHub when you have a working set of commits