Skip to content

Instantly share code, notes, and snippets.

@mattclements
Forked from oodavid/README.md
Created August 5, 2012 11:49

Revisions

  1. @oodavid oodavid revised this gist Jul 31, 2012. 1 changed file with 6 additions and 1 deletion.
    7 changes: 6 additions & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -91,7 +91,12 @@ After you've installed git, make sure it's a relatively new version - old script

    ### Set up service hook

    ***Sadly bitbucket does not (to my knowledge) have the option to ping a URL with a post-receive hook.***
    1. Go to: Repo > Admin > Services
    1. Select "POST"
    1. Add the URL to your deployment script - http://server.com/deploy.php
    1. Save

    ***Thanks to DrewAPicture in the comments for this one***

    # 4 - On the Server

  2. @oodavid oodavid revised this gist Mar 26, 2012. No changes.
  3. @oodavid oodavid revised this gist Mar 26, 2012. 1 changed file with 4 additions and 3 deletions.
    7 changes: 4 additions & 3 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,16 +1,17 @@

    # Deploy your site with git

    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, Java, Perl, RoR, JSP) scripts are served from /var/www/html/
    * 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***

    # 1 - On your local machine

    *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*
    @@ -117,4 +118,4 @@ Now you're ready to go :-)
    ## Sources
    * [Build auto-deploy with php and git(hub) on an EC2 Amazon AMI instance](https://gist.github.com/1105010) - who in turn referenced:
    * [ec2-webapp / INSTALL.md](https://github.com/rsms/ec2-webapp/blob/master/INSTALL.md#readme)
    * [How to deploy your code from GitHub automatically](http://writing.markchristian.org/how-to-deploy-your-code-from-github-automatic)
    * [How to deploy your code from GitHub automatically](http://writing.markchristian.org/how-to-deploy-your-code-from-github-automatic)
  4. @oodavid oodavid revised this gist Mar 26, 2012. 1 changed file with 61 additions and 38 deletions.
    99 changes: 61 additions & 38 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -13,83 +13,106 @@ This gist assumes:

    # 1 - On your local machine

    ## 1.1 - Grab a deployment script for your site
    *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*

    * [deploy.php](#file_deploy.php)
    * *other scripts yet to be written*
    ## Grab a deployment script for your site

    ## 1.2 - Add, commit and push this to github
    See [deploy.php](#file_deploy.php)

    git add deploy.php
    git commit -m 'Added the git deployment script'
    git push -u origin master
    ## Add, commit and push this to github

    git add deploy.php
    git commit -m 'Added the git deployment script'
    git push -u origin master

    # 2 - On your server

    ## 2.1 - Install git...
    *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*

    ## Install git...

    After you've installed git, make sure it's a relatively new version - old scripts quickly become problematic as github / bitbucket / whatever will have the latests and greatest, if you don't have a recent version you'll need to figure out how to upgrade it :-)

    git --version
    git --version

    ### ...on CentOS 5.6

    # Add a nice repo
    rpm -Uvh http://repo.webtatic.com/yum/centos/5/latest.rpm
    # Install git
    yum install --enablerepo=webtatic git-all
    # Add a nice repo
    rpm -Uvh http://repo.webtatic.com/yum/centos/5/latest.rpm
    # Install git
    yum install --enablerepo=webtatic git-all

    ### ...using generic yum

    sudo yum install git-core
    sudo yum install git-core

    ## Setup git

    ## 2.2 - Setup git
    git config --global user.name "Server"
    git config --global user.email "[email protected]"

    # Setup
    git config --global user.name "Server"
    git config --global user.email "[email protected]"
    ## Create an ssh directory for the apache user

    ## 2.3 - Create an ssh directory for the apache user
    sudo mkdir /var/www/.ssh
    sudo chown -R apache:apache /var/www/.ssh/

    sudo mkdir /var/www/.ssh
    sudo chown -R apache:apache /var/www/.ssh/
    ## Generate a deploy key for apache user

    ## 2.4 - Generate a deploy key for apache user
    sudo -Hu apache ssh-keygen -t rsa # choose "no passphrase"
    sudo cat /var/www/.ssh/id_rsa.pub

    sudo -Hu apache ssh-keygen -t rsa # choose "no passphrase"
    sudo cat /var/www/.ssh/id_rsa.pub
    # 3 - On your origin (github / bitbucket)

    # 3 - On your git origin (github / bitbucket)
    *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*

    ## Add the deploy key to your repo
    ## GitHub instructions

    1. https://github.com/you/yourapp/admin/keys
    1. Paste the deploy key you generated on the EC2 machine
    ### Add the SSH key to your user

    ##Set up service hook in github
    1. https://github.com/settings/ssh
    1. Create a new key
    1. Paste the deploy key you generated on the server

    1. https://github.com/oodavid/1DayLater/admin/hooks
    ### Set up service hook

    1. https://github.com/oodavid/server.com/admin/hooks
    1. Select the **Post-Receive URL** service hook
    1. Enter the URL to your update script - http://example.com/github.php
    1. Enter the URL to your deployment script - http://server.com/deploy.php
    1. Click **Update Settings**

    ## Bitbucket instructions

    ### Add the SSH key to your account

    1. https://bitbucket.org/account/ssh-keys/
    1. Create a new key
    1. Paste the deploy key you generated on the server

    ### Set up service hook

    ***Sadly bitbucket does not (to my knowledge) have the option to ping a URL with a post-receive hook.***

    # 4 - On the Server

    ## Pull the code
    *Here we clone the origin repo into a chmodded /var/www/html folder*

    ## Pull from origin

    cd /var/www/
    sudo chown -R apache:apache html
    sudo -Hu apache git clone [email protected]:you/yourapp.git html
    sudo chown -R apache:apache /var/www/html
    sudo -Hu apache git clone [email protected]:you/server.git /var/www/html

    # Rejoice!

    Now you're ready to go :-)

    ## Some notes

    * At this point you should be able to push to github and your site will automatically pull down code from github
    * You can manually trigger a pull by hitting http://example.com/github.php in your browser etc (you'll see the output too)
    * It would be trivial to setup another repo on your EC2 box for different branches (develop, release-candidate etc) - repeat most of the steps but checkout a branch after pulling the repo down
    * Navigate the the deployment script to trigger a pull and see the output:
    * http://server.com/deploy.php
    * ***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

    ## Sources
    * [Build auto-deploy with php and git(hub) on an EC2 Amazon AMI instance](https://gist.github.com/1105010) - who in turn referenced:
  5. @oodavid oodavid revised this gist Mar 26, 2012. 1 changed file with 49 additions and 42 deletions.
    91 changes: 49 additions & 42 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,58 +1,65 @@
    # Auto-deploy with php and git(hub) on an EC2 Amazon AMI

    # Deploy your site with git

    This gist assumes:

    * you have a local repo
    * that pushes to a **private** github repo (origin)
    * and an EC2 Amazon AMI instance with LAMP running
    * Your webpages are served from /var/www/html/
    * 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, Java, Perl, RoR, JSP) 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)***

    # 1 - On your local machine

    ## Create the update script
    ## 1.1 - Grab a deployment script for your site

    * [deploy.php](#file_deploy.php)
    * *other scripts yet to be written*

    ## 1.2 - Add, commit and push this to github

    git add deploy.php
    git commit -m 'Added the git deployment script'
    git push -u origin master

    # 2 - On your server

    ## 2.1 - Install git...

    After you've installed git, make sure it's a relatively new version - old scripts quickly become problematic as github / bitbucket / whatever will have the latests and greatest, if you don't have a recent version you'll need to figure out how to upgrade it :-)

    The script I use is a little "verbose" in that I wanted a sanity check: it outputs the current directory, the user and then some git commands. Create a local file **github.php** with the following contents:
    git --version

    <?php
    /**
    * GitHub.php
    *
    * Used for automatically deploying websites via github, more deets here:
    *
    * https://gist.github.com/1809044
    */
    echo shell_exec('echo $PWD');
    echo '<br />';
    echo shell_exec('whoami');
    echo '<br />';
    echo shell_exec('git pull');
    echo '<br />';
    echo shell_exec('git status');
    ### ...on CentOS 5.6

    Add, commit and push this to github
    # Add a nice repo
    rpm -Uvh http://repo.webtatic.com/yum/centos/5/latest.rpm
    # Install git
    yum install --enablerepo=webtatic git-all

    git add github.php
    git commit -m 'Added the github update script'
    git push -u origin master
    ### ...using generic yum

    # 2 - On the EC2 Machine
    sudo yum install git-core

    ## Install git
    ## 2.2 - Setup git

    sudo yum install git-core
    # Setup
    git config --global user.name "Server"
    git config --global user.email "[email protected]"

    ## Create an ssh directory for the apache user
    ## 2.3 - Create an ssh directory for the apache user

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

    ## Generate a deploy key for apache user
    ## 2.4 - Generate a deploy key for apache user

    sudo -Hu apache ssh-keygen -t rsa # choose "no passphrase"
    sudo cat /var/www/.ssh/id_rsa.pub
    sudo -Hu apache ssh-keygen -t rsa # choose "no passphrase"
    sudo cat /var/www/.ssh/id_rsa.pub

    # 3 - On GitHub.com
    # 3 - On your git origin (github / bitbucket)

    ## Add the deploy key to your repo

    @@ -66,13 +73,13 @@ Add, commit and push this to github
    1. Enter the URL to your update script - http://example.com/github.php
    1. Click **Update Settings**

    # 4 - On the EC2 Machine
    # 4 - On the Server

    ## Pull the repo
    ## Pull the code

    cd /var/www/
    sudo chown -R apache:apache html
    sudo -Hu apache git clone [email protected]:you/yourapp.git html
    cd /var/www/
    sudo chown -R apache:apache html
    sudo -Hu apache git clone [email protected]:you/yourapp.git html

    # Rejoice!

  6. @oodavid oodavid revised this gist Mar 26, 2012. 1 changed file with 50 additions and 0 deletions.
    50 changes: 50 additions & 0 deletions deploy.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,50 @@
    <?php
    /**
    * GIT DEPLOYMENT SCRIPT
    *
    * Used for automatically deploying websites via github or bitbucket, more deets here:
    *
    * https://gist.github.com/1809044
    */

    // The commands
    $commands = array(
    'echo $PWD',
    'whoami',
    'git pull',
    'git status',
    'git submodule sync',
    'git submodule update',
    'git submodule status',
    );

    // Run the commands for output
    $output = '';
    foreach($commands AS $command){
    // Run it
    $tmp = shell_exec($command);
    // Output
    $output .= "<span style=\"color: #6BE234;\">\$</span> <span style=\"color: #729FCF;\">{$command}\n</span>";
    $output .= htmlentities(trim($tmp)) . "\n";
    }

    // Make it pretty for manual user access (and why not?)
    ?>
    <!DOCTYPE HTML>
    <html lang="en-US">
    <head>
    <meta charset="UTF-8">
    <title>GIT DEPLOYMENT SCRIPT</title>
    </head>
    <body style="background-color: #000000; color: #FFFFFF; font-weight: bold; padding: 0 10px;">
    <pre>
    . ____ . ____________________________
    |/ \| | |
    [| <span style="color: #FF0000;">&hearts; &hearts;</span> |] | Git Deployment Script v0.1 |
    |___==___| / &copy; oodavid 2012 |
    |____________________________|

    <?php echo $output; ?>
    </pre>
    </body>
    </html>
  7. @oodavid oodavid revised this gist Feb 12, 2012. 1 changed file with 10 additions and 2 deletions.
    12 changes: 10 additions & 2 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -14,10 +14,18 @@ This gist assumes:
    The script I use is a little "verbose" in that I wanted a sanity check: it outputs the current directory, the user and then some git commands. Create a local file **github.php** with the following contents:

    <?php
    echo shell_exec('whoami');
    echo '<br />';
    /**
    * GitHub.php
    *
    * Used for automatically deploying websites via github, more deets here:
    *
    * https://gist.github.com/1809044
    */
    echo shell_exec('echo $PWD');
    echo '<br />';
    echo shell_exec('whoami');
    echo '<br />';
    echo shell_exec('git pull');
    echo '<br />';
    echo shell_exec('git status');
  8. @oodavid oodavid revised this gist Feb 12, 2012. No changes.
  9. @oodavid oodavid revised this gist Feb 12, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    # Auto-deploy with php and git(hub) on an EC2 Amazon AMI instance
    # Auto-deploy with php and git(hub) on an EC2 Amazon AMI

    This gist assumes:

  10. @oodavid oodavid revised this gist Feb 12, 2012. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    # Auto-deploy with php and git(hub) on an EC2 Amazon AMI instance

    This gist assumes:

    * you have a local repo
  11. @oodavid oodavid revised this gist Feb 12, 2012. 1 changed file with 1 addition and 3 deletions.
    4 changes: 1 addition & 3 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,11 +1,9 @@
    A slight modification of [Build auto-deploy with php and git(hub) on an EC2 Amazon AMI instance](https://gist.github.com/1105010)

    This gist assumes:

    * you have a local repo
    * that pushes to a **private** github repo (origin)
    * and an EC2 Amazon AMI instance with LAMP running
    * Your webpage are served from /var/www/html/
    * Your webpages are served from /var/www/html/

    # 1 - On your local machine

  12. @oodavid oodavid revised this gist Feb 12, 2012. 1 changed file with 66 additions and 35 deletions.
    101 changes: 66 additions & 35 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,51 +1,82 @@
    Kind of continue from the other gist [how to install LAMP on an Amazon AMI](https://gist.github.com/1105007)
    A slight modification of [Build auto-deploy with php and git(hub) on an EC2 Amazon AMI instance](https://gist.github.com/1105010)

    ##Install git
    This gist assumes:

    ```
    sudo yum install git-core
    ```
    * you have a local repo
    * that pushes to a **private** github repo (origin)
    * and an EC2 Amazon AMI instance with LAMP running
    * Your webpage are served from /var/www/html/

    ##Create ssh directory since it doesn't exists by default on the Amazon AMI
    # 1 - On your local machine

    ```
    sudo mkdir /var/www/.ssh
    sudo chown -R apache:apache /var/www/.ssh/
    ```
    ## Create the update script

    ##Generate key for apache user
    The script I use is a little "verbose" in that I wanted a sanity check: it outputs the current directory, the user and then some git commands. Create a local file **github.php** with the following contents:

    ```
    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
    ```
    <?php
    echo shell_exec('whoami');
    echo '<br />';
    echo shell_exec('echo $PWD');
    echo '<br />';
    echo shell_exec('git pull');
    echo '<br />';
    echo shell_exec('git status');

    ##Get the repo
    Add, commit and push this to github

    ```
    cd /var/www/
    sudo chown -R apache:apache html
    sudo -Hu apache git clone [email protected]:yourUsername/yourApp.git html
    ```
    git add github.php
    git commit -m 'Added the github update script'
    git push -u origin master

    ##Setup the update script
    # 2 - On the EC2 Machine

    ```
    sudo -Hu apache nano html/update.php
    ```
    ## Install git

    ```
    <?php `git pull`; ?>
    ```
    sudo yum install git-core

    ## Create an ssh directory for the apache user

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

    ## Generate a deploy key for apache user

    sudo -Hu apache ssh-keygen -t rsa # choose "no passphrase"
    sudo cat /var/www/.ssh/id_rsa.pub

    # 3 - On GitHub.com

    ## Add the deploy key to your repo

    1. https://github.com/you/yourapp/admin/keys
    1. Paste the deploy key you generated on the EC2 machine

    ##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.
    1. https://github.com/oodavid/1DayLater/admin/hooks
    1. Select the **Post-Receive URL** service hook
    1. Enter the URL to your update script - http://example.com/github.php
    1. Click **Update Settings**

    # 4 - On the EC2 Machine

    ## Pull the repo

    cd /var/www/
    sudo chown -R apache:apache html
    sudo -Hu apache git clone [email protected]:you/yourapp.git html

    # Rejoice!

    Now you're ready to go :-)

    ## Some notes

    ##Sources
    * At this point you should be able to push to github and your site will automatically pull down code from github
    * You can manually trigger a pull by hitting http://example.com/github.php in your browser etc (you'll see the output too)
    * It would be trivial to setup another repo on your EC2 box for different branches (develop, release-candidate etc) - repeat most of the steps but checkout a branch after pulling the repo down

    * [ec2-webapp / INSTALL.md](https://github.com/rsms/ec2-webapp/blob/master/INSTALL.md#readme)
    * [How to deploy your code from GitHub automatically](http://writing.markchristian.org/how-to-deploy-your-code-from-github-automatic)
    ## Sources
    * [Build auto-deploy with php and git(hub) on an EC2 Amazon AMI instance](https://gist.github.com/1105010) - who in turn referenced:
    * [ec2-webapp / INSTALL.md](https://github.com/rsms/ec2-webapp/blob/master/INSTALL.md#readme)
    * [How to deploy your code from GitHub automatically](http://writing.markchristian.org/how-to-deploy-your-code-from-github-automatic)
  13. @aronwoost aronwoost created this gist Jul 25, 2011.
    51 changes: 51 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,51 @@
    Kind of continue from the other gist [how to install LAMP on an Amazon AMI](https://gist.github.com/1105007)

    ##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 [email protected]:yourUsername/yourApp.git html
    ```

    ##Setup the update script

    ```
    sudo -Hu apache nano html/update.php
    ```

    ```
    <?php `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

    * [ec2-webapp / INSTALL.md](https://github.com/rsms/ec2-webapp/blob/master/INSTALL.md#readme)
    * [How to deploy your code from GitHub automatically](http://writing.markchristian.org/how-to-deploy-your-code-from-github-automatic)