The most important: You must have shell access!
This gist assumes:
- you have a local git repo
- with an online remote repository (github / bitbucket etc)
- and a cloud server (Rackspace cloud / Amazon EC2 etc)
- your (PHP) scripts are served from /var/www/html/
- your webpages are executed by apache
- apache's home directory is /var/www/
- (this describes a pretty standard apache setup on Redhat / Ubuntu / CentOS / Amazon AMI etc)
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
Here we install and setup git on the server, we also create an SSH key so the server can talk to the origin without using passwords etc
To check run in shell account command
git --version
ssh-keygen -t rsa # choose "no passphrase"
#Enter file in which to save the key (/home/[user]/.ssh/id_rsa): #Rewrite this Path!
Here we add the SSH key to the origin to allow your server to talk without passwords. In the case of GitHub we also setup a post-receive hook which will automatically call the deploy URL thus triggering a PULL request from the server to the origin
- https://github.com/settings/ssh
- Create a new key
- Paste the deploy key you generated on the server
- https://github.com/oodavid/server.com/admin/hooks
- Select the Post-Receive URL service hook
- Enter the URL to your deployment script - http://server.com/deploy.php?key=[RANDOM_KEY]
- Click Update Settings
- https://bitbucket.org/account/ssh-keys/
- Create a new key
- Paste the deploy key you generated on the server
- Go to: Repo > Admin > Services
- Select "POST"
- Add the URL to your deployment script - http://server.com/deploy.php
- Save
git remote add origin ssh://[email protected]/project.git
git fetch
git pull origin master
Now you're ready to go :-)
- If you have forced redirect to /web or /public_html in project create deploy.php in folder that you have .git folder and in public folder create symlink deplay.php to your deploy file.
- Navigate the the deployment script to trigger a pull and see the output:
- http://server.com/deploy.php?key=[RANDOM_KEY]
- this is useful for debugging too ;-)
- When you push to GitHub your site will automatically ping the above url (and pull your code)
- When you push to Bitbucket you will need to manually ping the above url
- 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