Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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

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

@ryhanson

This comment has been minimized.

Show comment Hide comment
@ryhanson

ryhanson Apr 15, 2013

It asks me for the ec2-user password when I run: sudo -Hu apache ...

It asks me for the ec2-user password when I run: sudo -Hu apache ...

@clouddueling

This comment has been minimized.

Show comment Hide comment
@clouddueling

clouddueling Aug 14, 2013

I have the same problem with it asking for ec2-user password

I have the same problem with it asking for ec2-user password

@thewebwing

This comment has been minimized.

Show comment Hide comment
@thewebwing

thewebwing Aug 21, 2013

I had to do a little digging myself. I forgot that on an EC2 instance, all you have to do is type sudo su to become root. Then you can run sudo commands to your heart's content.

Since you will likely want to step out of the root role (you should when you're done, even if you don't want to), you can run su ec2-user to get back to where you were.

I had to do a little digging myself. I forgot that on an EC2 instance, all you have to do is type sudo su to become root. Then you can run sudo commands to your heart's content.

Since you will likely want to step out of the root role (you should when you're done, even if you don't want to), you can run su ec2-user to get back to where you were.

@sharat

This comment has been minimized.

Show comment Hide comment
@sharat

sharat Oct 7, 2014

Is this is a safe mechanism? Like putting an update script in the root folder?

sharat commented Oct 7, 2014

Is this is a safe mechanism? Like putting an update script in the root folder?

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