Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

my question is basically two questions, but since they are closely related I thought that it makes sense to ask them en-bloque.

Case:
I am running a webapplication, which is distributed over multiple AWS EC2 instances behind a AWS Elastic Load Balancer

Intended goals:
a) When deploying new app code (php) it should be automatically distributed to all EC2 instances.
b) When new EC2 instances are added, they should automatically "bootstrap" with the latest appcode

My thoughts so far:
ad a)
phing (http://phing.info) is probably the answer for this part. i would probably add multiple targets for each EC2 instance and when running a deploy it would deploy to all machines. probably unfortunately not in parallel. but that might be even beneficial when scripting it in a way where the EC2 instance is "paused" in the load balancer, upgraded, "unpaused" again and on to the next instance.

ad b)
not sure how i would achieve that. in a conventional "hardware based setup" i probably had a "app code" volume on a network storage device and when adding a new server i'd simply attach that volume. when deploying new appcode i had just one deploy operation to this volume. so i need some "central storage" from where the newly bootstrapped machine/instance downloads it's appcode. i thought about git, but after all git is not a deploy tool and probably shouldn't be forced to be used as one.

I'd be happy to see your setups for such tasks and hear your hints and ideas for such a situation.

Thanks,

Joshua

like image 382
Joshua Avatar asked Feb 15 '11 12:02

Joshua


1 Answers

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.

like image 186
Kåre Werner Storgaard Avatar answered Nov 05 '22 04:11

Kåre Werner Storgaard