I am wanting to move all of my sites to GitHub for all of the obvious benefits. I am not a big fan of the command line, so I like GitHub because it allows me to avoid touching all of that. Setting up a repository on GitHub and then syncing it with my computer is easy enough. I need to be able to push from GitHub to the webserver automatically though so when I update something locally to the main branch, sync it with GitHub, it goes live on the site. From Googling the subject it seems like most of the techniques either require the command line or seem fairly complex. I want to do this with about 15-20 sites (many of which are hosted on different servers from different clients). I want to find an option that is within my skill set and doesn't take 2-3 hours per site. Anyone know of the best, easiest way to set this up?
-
5The first step would be to learn how to use command line. You're heading to some quite elaborated schema, and without using command line you won't get very far. Also, be careful, there's probably some files you won't put in github (images and documents may not require source control) aswell as the databases to deploy, and it won't be done like magic... I think what you should look for is a deploy tool – Laurent S. Jun 28 '13 at 14:41
-
Whether using OSX, you can consider this GUI-based pretty convenient workflow (I also use this for some WordPress stuff): http://eppz.eu/blog/push-git-to-ftp/ – Geri Borbás Jul 02 '13 at 16:44
-
You may want look into using a PAAS like https://www.heroku.com/ which supports deploy through a simple push i.e. `git push heroku master` – Brandon Zacharie Nov 29 '13 at 09:38
3 Answers
The part which is complex is the webhook on GitHub
Every GitHub repository has the option to communicate with a web server whenever the repository is pushed to.
That means your web site must have a process listening to those JSON messages sent by GitHub upon reception of a commit.
You can see multiple examples of those listeners, like this webhook-deployer, with an auto.php (for a php server):
<?php
// Prevent accidental XSS
header("Content-type: text/plain");
// Run the script
if ( $_POST['payload'] ) {
shell_exec("./pull.sh");
}
That GitHub project recommends an SSH key with no passphrase, which I agree at first (to test it out).
However, especially for private projects, it is best to run an ssh-agent and manage an ssh key passphrase protected.
As janos comments:
- If the GitHub repository is public, then he doesn't even need one.
- If the repo is private, then he needs it, but this should not be taken so lightly. If possible he should use a key agent.
If that's too complicated then he could use a dedicated SSH key without passphrase just for this deployment, and that key should never leave the deployment PC.
-
1Why do you encourage SSH keys without a passphrase? If the GitHub repository is public, then he doesn't even need one. If the repo is private, then he needs it, but this should not be taken so lightly. If possible he should use a key agent. If that's too complicated then he could use a dedicated SSH key without passphrase just for this deployment, and that key should never leave the deployment PC. – janos Nov 23 '13 at 06:07
-
@janos very good points. I have amended the answer and included your points in it, for more visibility. – VonC Nov 23 '13 at 10:26
I know this ticket is old, but for those who find this somehow, checkout dploy.io. It's a hosted service made specifically for the purpose of deploying your repo from GitHub/Bitbucket to your server. It supports SFTP/FTP/S3/Heroku/SSH commands and more.
Disclaimer: I work on dploy.io

- 118
- 2
- 5
You might want to take a look at this PHP script:
https://github.com/JohannesHoppe/easy-git-deploy
(It does a git clone, git pull, git push for you)
Since several years I manage all my wordpress installations with that script.
Hint: If you are using a shared hosting environment, than script limits might break the first execution. In that case, login via SSH and do the first clone manually:
git clone 'https://user:passwort@//github.com/user/repo.git'
Here you can also manually confirm the SSH key fingerprint.
Second hint: You should secure the directory with a .htaccess / .htpasswd file.

- 251
- 3
- 10