Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Deploy and Scale your PHP App with AWS ElasticBeanstalk and Docker- PHPTour Luxembourg 2015


Published on

Deploy and scale your PHP Application with AWS ElasticBeanstalk and Docker

Published in: Software
  • Dating direct: ❤❤❤ ❤❤❤
    Are you sure you want to  Yes  No
    Your message goes here
  • Follow the link, new dating source: ❤❤❤ ❤❤❤
    Are you sure you want to  Yes  No
    Your message goes here

Deploy and Scale your PHP App with AWS ElasticBeanstalk and Docker- PHPTour Luxembourg 2015

  1. 1. Deploy and Scale your PHP App using Docker containers and AWS Beanstalk Walter Dal Mut @walterdalmut -
  2. 2. I'm co-founder of @CorleyCloud application development infrastructure and application migration on cloud I'm also a co-founder of @UpCloo U.K. based startup: powering related content across the web
  3. 3. First of all we have to agree on what scaling is for this talk
  4. 4. scalability is not high availability Scalability is the ability of a system to handle a growing amount of work in capable manner or the ability to be enlarged to accomodate that growth (from wikipedia)
  5. 5. Adapting Infrastructures
  6. 6. From single instances point of view
  7. 7. It is also meaning that with fixed hardware we have to provide the highest computing capacity
  8. 8. Money wasters?
  9. 9. With Cloud Providers
  10. 10. About ElasticBeanstalk Load Balanced web applications Single instance web applications Queue daemons (SQS)
  11. 11. Load balanced web applications
  12. 12. Autoscalable infrastructures
  13. 13. thresholds are used to create and remove instances
  14. 14. with (auto)scalable infrastructures How to manage application upgrades How to monitor servers How to handle servers configurations How to handle instances logs ... ElasticBeanstalk help us with this things
  15. 15. Application Deploy
  16. 16. Mainly Beanstalk takes a ZIP artifact (the PHP application) and unpack it into the environment Uses YML definitions in order to setup the environment
  17. 17. The deploy cycle take care of: 1. Packages 2. Users & Groups 3. Files 4. Commands before the application and web server are set up 5. Services 6. Container_commands just before the application version is deployed
  18. 18. Configure PHP details files:   "/etc/php.d/my­timezone.ini" :     mode: "000644"     owner: root     group: root     content: |       date.timezone = Europe/Rome You can also use beanstalk options
  19. 19. extract your application logs commands:     21_application_logs:         command: echo "/var/app/current/app/logs/*.log" > app.conf         cwd: /opt/elasticbeanstalk/tasks/bundlelogs.d     22_application_logs:         command: echo "/var/app/current/app/logs/*.log" > app.conf         cwd: /opt/elasticbeanstalk/tasks/systemtaillogs.d     23_application_logs:         command: echo "/var/app/current/app/logs/*.log" > app.conf         cwd: /opt/elasticbeanstalk/tasks/taillogs.d     24_application_logs:         command: echo "/var/app/current/app/logs/*.log" > app.conf         cwd: /opt/elasticbeanstalk/tasks/publishlogs.d And check them directly from the web console
  20. 20. Beanstalk works with different application containers PHP, Node.js, Tomcat, Python, Ruby and... Docker & Multicontainer Docker Multicontainer Docker is connected to ElasticContainer Service
  21. 21. Why docker is interesting for ElasticBeanstalk? When there is a default PHP container with different available versions: 5.3, 5.4, 5.5, 5.6
  22. 22. Instances are Amazon Linux Difficult to configure a different distro: ubuntu, debian ... Even packages: supervisors, agents etc. Difficult to replicate the env locally (dev).
  23. 23. Default PHP container configuration {{ Apache - MOD_PHP }}
  24. 24. The application path change after the deploy cycle /var/app/ondeck->/var/app/current Symfony2 cache warmup problems...
  25. 25. With Docker we can create a more dedicated setup {{ Nginx - PHP-FPM }}
  26. 26. The docker environment is more stable and testable than the default one Thanks to the docker isolation nature File are uncompressed into: /var/app/current
  27. 27. Prepare a web server FROM ubuntu:14.04 RUN apt­get update && apt­get install ­y php5 apache2 libapache2­mod­php5      php5­apcu php5­curl php5­mongo php5­xsl && rm ­rf /var/lib/apt/lists/* RUN a2enmod rewrite deflate expires headers EXPOSE 80 CMD ["/usr/sbin/apache2ctl", "­D", "FOREGROUND"] prepare your Dockerfile
  28. 28. You can build the container during the deploy cycle Just let the `Dockerfile` in the root folder of your project
  29. 29. dockerbuild-twdalmut/webserver. dockerpush
  30. 30. Docker containers are engaged with: + automated builds! (keep container up to date automatically) Already provisioned containers
  31. 31. You can use it for your development dockerpullwdalmut/webserver dockerrun   -p8080:80   -v`pwd`:/var/www/html   -dwdalmut/webserver Use Vagrant docker provisioner for your dev environments
  32. 32. Same environment in ElasticBeanstalk {   "AWSEBDockerrunVersion": "1",   "Image": {     "Name": "wdalmut/webserver",     "Update": "true"   },   "Ports": [     {       "ContainerPort": "80"     }   ],   "Volumes": [     {       "HostDirectory": "/var/app/current",       "ContainerDirectory": "/var/www/html"     }   ],   "Logging": "/var/log/app" }
  33. 33. Beanstalk proxies with nginx your first exposed port 80->EXPOSE*****[,******]
  34. 34. Ok, we have the infrastructure And about the application setup?
  35. 35. App tuning with environment variables <?php $env=getenv("SYMFONY__ENV");
  36. 36. download config files from S3 Resources:     AWSEBAutoScalingGroup:         Type: "AWS::AutoScaling::AutoScalingGroup"         Metadata:             AWS::CloudFormation::Authentication:                 S3AccessCred:                     type: "S3"                     roleName: "aws­elasticbeanstalk­ec2­role"                     buckets: "myapp­deploy" files:     "/root/parameters.yml":         mode: "000400"         owner: root         group: root         source: https://s3­eu­west­­deploy/parameters.yml container_commands:      01_copy_configuration:          command: cp /root/parameters.yml app/config/parameters.yml remember that EC2 IAM roles should be configured correctly
  37. 37. EC2 Role configuration {     "Version": "2012­10­17",     "Statement": [         {             "Sid": "Stmt1305192283000",             "Effect": "Allow",             "Action": [                 "s3:*"             ],             "Resource": [                 "arn:aws:s3:::app­deploy/",                 "arn:aws:s3:::app­deploy/*"             ]         }     ] } Could be more detailed and restricted than this example
  38. 38. You cannot use PHP from the host (it is in the docker container)... You have to pass commands via docker containers dockerrun   --rm-i-t   -v/var/app/current:/var/www/html   wdalmut/webserver   app/consoleca:cl-e=prod
  39. 39. Thanks for listening