Deploying a PHP webapp to multiple EC2 instances behind a Elastic Load Balancer Deploying a PHP webapp to multiple EC2 instances behind a Elastic Load Balancer php php

Deploying a PHP webapp to multiple EC2 instances behind a Elastic Load Balancer


This could be made using phing. However, I'm not sure why you want new instances to automatically retrieve the appcode? Do you get extra instance very often? And in order for a) to deploy code to several instances, it would still need to know them?

This setup requires a master deploy server and uses a push strategy. The master server needs phing, any required phing packages, and optionally ssh keys for the EC2 instances.

Suggestion for a)

(This is just a general outline of the phing tasks required)

  • Retrieve instance list (either config file or suuplied parameters)
  • Export appcode from repository to master server(e.g. SubVersion)
  • Tar appcode
  • scp tarball to all EC2 instances (to a deploy folder)
  • With rsh unpack tarball on EC2 instances
  • With rsh update symbolic link on EC2 instances so webserver folder points at new deploy folder
  • Clear any caches on webserver

The above could be called after you have made a new release.

Suggestion for b) This could be achieved by running the phing script every couple of hours, have it login to the EC2 instances and check for the appcode. If it doesn't find it, it will deploy the newest final release.This of course, requires the EC2 instances to be setup correctly in regard to webservers, config files, etc. (However, this could also be achieved by remote shell via phing).

I've previously used similar setups, but haven't tried it with services like EC2.


a) Take a look a Capistrano and since you're not using Ruby (and RoR) use the railsless-deploy plugin. Capistrano can deploy to multiple servers.

b) Haven't gotten any experience with this, but I wouldn't be surprised if there isn't a plugin/gem for Capistrano that can pretty much do this for you.


I believe phing is a good tool for this. Capistrano might also help.

I deploy my application in a very similar environment. So far, I've been using simple bash scirpts, but I'll probably be moving towards a phing based solution, mostly because of the difficulty involved in developing shell scripts (you have to know a new syntax that's not very flexible, not to mention cross-platform) and the availability of parallel processing, which is present in phing.