Deploy a Symfony project on Amazon Elastic Beanstalk (English)


  symfony    english    amazon    deployment 

We will deploy an application using Symfony framework (with a Git repository) using an Amazon Elastic Beanstalk application type, one of Amazon Web Services service.

Amazon Elastic Beanstalk can deploy an application and auto-scale the platform depending on the load you are using or you need. You can also manage multiple environments for your application.

Amazon has created a package with useful tools to deploy your app named AWS Dev Tools.

Download and installation of AWS Dev Tools

Remember to get the latest available version on the following page:

Install those tools in the /opt directory and add executables directories in the PATH environment variable:

$ sudo wget -O /opt/
$ sudo unzip -d /opt /opt/
$ export PATH=$PATH:/opt/AWS-ElasticBeanstalk-CLI-2.5.1/api/bin/:/opt/AWS-ElasticBeanstalk-CLI-2.5.1/eb/linux/python2.7/

AWS Dev Tools are now ready to use.

Configure your Git repository to deploy your application

We will now use a setup tool available in the AWS Dev Tools package to prepare the Git repository and add some commands to it.

To do that, go to the root directory of your Git repository project and type:

$ /opt/AWS-ElasticBeanstalk-CLI-2.5.1/AWSDevTools/Linux/

No output should appear but you must have a new AWSDevTools subdirectory in the .git directory. Verify with:

$ ls .git/AWSDevTools
aws  aws.elasticbeanstalk.config  aws.elasticbeanstalk.push

Your Git is ready, you can know use those new git commands :

git aws.config : to configure your Amazon identifiers (Access key & Secret key) and specify your application/environment name,

git aws.push : to push your repository content on your Amazon Elastic Beanstalk application.

Configure your git project by typing the git aws.config command:

$ git aws.config
AWS Access Key: 
AWS Secret Key: 
AWS Region [default to us-east-1]:
AWS Elastic Beanstalk Application: 
AWS Elastic Beanstalk Environment: 
NOTE: "git aws.push" will use the credentials found in the following file:
You can supply different credentials by editing that file or editing
.elasticbeanstalk/config to reference a different file.  The file should
have the following format:
AWSAccessKeyId=your key
AWSSecretKey=your secret

As the output says, a new file with your Amazon API identifiers (Access key and Secret key) has been created in the following path: /home//.elasticbeanstalk/aws_credential_file.

Also please note that the .elasticbeanstalk directory has been automatically added to your .gitignore file.

Deploy the app!

You just had to type the following command:

$ git aws.push

The Amazon AMI images for Amazon Elastic Beanstalk already has some useful hooks installed on during deploying as they automatically run composer install when a composer.json file is found on the root project path.

You can list all available hooks by connecting on the server and typing:

$ ls -R /opt/elasticbeanstalk/hooks/appdeploy/
enact  pre

Define custom deployment hooks

Amazon permit you to write custom deployment hooks by adding files named .config in a .ebextensions directory on your repository root project path.

They will be executed in alphabetically order (protip: you can prefix them with a number: 01installcomposer.config, 02assetsinstall.config, etc ...).

Configuration files must be written in YAML format and can have multiple commands in them, executed in alphabetically order too. See this example:

    command: "composer.phar self-update"
    leader_only: true
    command: "cd /var/app/ondeck/html/ && composer.phar install --prefer-source"
    leader_only: true

For your information please note that during application deployment the action takes place in the /var/app/ondeck/ directory and when deployment is finished (and succeed) the application is available in /var/app/current/.

You can also define environment variables in them, create users, install packages, etc ... for more information on available syntaxes, go to: