This document discusses how to scale a PHP application using ElasticBeanstalk. ElasticBeanstalk allows running applications across dynamically sized fleets of EC2 instances that are managed using simple configuration files. It handles tasks like deploying code and configuration changes, monitoring and scaling application traffic. Some key points discussed include running different environments for development, testing and production; using Composer to manage dependencies and configuration; customizing using .ebextensions files; and monitoring and collecting logs.
5. Scale apps is not simple
How to handle dev/testing/production? (dynamic env)
How to install/update softwares? (dynamic env)
How to handle user sessions? (more than one node)
How to handle/tail logs? (dynamic env)
How to monitor all instances (dynamic env)
And more... (all things are moving!)
17. Application variables
All environment variables are ported to your application in $_SERVER
You can pass everything like: Memcached and Mysql configurations etc.
18. Use Composer for Dependencies
ElasticBeanstalk uses composer in order to prepare your application
Use composer hooks in order to connect all env variables to your app
configuration
20. <?php
namespace CorleyDeploy;
use ComposerScriptEvent;
class Magento
{
public static function updateConf(Event $event)
{
if (array_key_exists("OVERWRITE_CONF", $_SERVER)) {
// Update your config file when $_SERVER contains "OVERWRITE_CONF" variable
}
}
}
21. Need more customizations?
Create a folder in your project root with name .ebextensions and
append your configuration files with extension .config
ElasticBeanstalk will use them during the application provisioning
22. Cronjobs runs on the leader instance only
.ebextensions/05_cron_jobs.config
container_commands:
01_magento_cron_job:
command: "cat .ebextensions/magento_cron_job.txt > /etc/cron.d/magento_cron_job && chmod 644 /etc/cron.d/magento_cron_leader_only: true
All configuration files are just simple YAML files
23. Monitor your environment
You can monitor many metrics with CloudWatch
UDP/IP CloudWatch agent on local machine: https://github.com/wdalmut/cloudwatch-agent
27. Collecting all application logs
AWS ELB can store all logs into a S3 bucket using a scheduled system
COST-SAVING! we don't need to propagate logs via "rsyslog"