Skip to content

Instantly share code, notes, and snippets.

@patricksan
Forked from nihaopaul/README.md
Created April 20, 2012 10:07
Show Gist options
  • Select an option

  • Save patricksan/2427549 to your computer and use it in GitHub Desktop.

Select an option

Save patricksan/2427549 to your computer and use it in GitHub Desktop.
Build auto-deploy with php and git(hub) on an EC2 Amazon AMI instance

Kind of continue from the other gist how to install LAMP on an Amazon AMI

##Install git

sudo yum install git-core

##Create ssh directory since it doesn't exists by default on the Amazon AMI

sudo mkdir /var/www/.ssh
sudo chown -R apache:apache /var/www/.ssh/

##Generate key for apache user

sudo -Hu apache ssh-keygen -t rsa  # chose "no passphrase"
sudo cat /var/www/.ssh/id_rsa.pub
# Add the key as a "deploy key" at https://github.com/you/myapp/admin

##Get the repo

cd /var/www/
sudo chown -R apache:apache html
sudo -Hu apache git clone git@github.com:yourUsername/yourApp.git html

##Setup the update script if you have multiple branches you wish to checkout only if that branch is updated, then change 'master'

sudo -Hu apache nano html/update.php
<?php

if (isset($_POST['payload'])) {
  
  $array = json_decode($_POST['payload']);
  if ( strpos($array['ref'], 'master') === TRUE ) {
    /* pull the git */
    `git pull`; 
  }
}

?>

##Set up service hook in github

  1. Go to Repository Administration for your repo (http://github.com/username/repository/admin)
  2. Click Service Hooks, and you'll see a list of available services. Select Post-Receive URL.
  3. Enter the URL for your update script (e.g. http://example.com/update.php) and click Update Settings.

##Sources

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment