AWS Elastic Beanstalk
Developer Guide

Deploying a Symfony Application to Elastic Beanstalk

Symfony is an open source framework for developing dynamic PHP web applications. This tutorial walks you through the process of generating a Symfony application and deploying it to an AWS Elastic Beanstalk environment.


This tutorial assumes that you have some knowledge of basic Elastic Beanstalk operations and the Elastic Beanstalk console. If you haven't already, follow the instructions in Getting Started Using Elastic Beanstalk to launch your first Elastic Beanstalk environment.

To follow the procedures in this guide, you will need a command line terminal or shell to run commands. Commands are shown in listings preceded by a prompt symbol ($) and the name of the current directory, when appropriate:

~/eb-project$ this is a command this is output

On Linux and macOS, use your preferred shell and package manager. On Windows 10, you can install the Windows Subsystem for Linux to get a Windows-integrated version of Ubuntu and Bash.

Symfony 4.3 requires PHP 7.1 or later and the intl extension for PHP. In this tutorial we use PHP 7.2 and the corresponding Elastic Beanstalk platform version. Install PHP and Composer by following the instructions at Setting Up your PHP Development Environment.

Launch an Elastic Beanstalk Environment

Use the AWS Management Console to create an Elastic Beanstalk environment. Choose the PHP platform and accept the default settings and sample code.

To launch an environment (console)

  1. Open the Elastic Beanstalk console using this preconfigured link:

  2. For Platform, choose the platform that matches the language used by your application.

  3. For Application code, choose Sample application.

  4. Choose Review and launch.

  5. Review the available options. When you're satisfied with them, choose Create app.

Environment creation takes about 5 minutes and creates the following resources:

  • EC2 instance – An Amazon Elastic Compute Cloud (Amazon EC2) virtual machine configured to run web apps on the platform that you choose.

    Each platform runs a specific set of software, configuration files, and scripts to support a specific language version, framework, web container, or combination of these. Most platforms use either Apache or nginx as a reverse proxy that sits in front of your web app, forwards requests to it, serves static assets, and generates access and error logs.

  • Instance security group – An Amazon EC2 security group configured to allow inbound traffic on port 80. This resource lets HTTP traffic from the load balancer reach the EC2 instance running your web app. By default, traffic isn't allowed on other ports.

  • Load balancer – An Elastic Load Balancing load balancer configured to distribute requests to the instances running your application. A load balancer also eliminates the need to expose your instances directly to the internet.

  • Load balancer security group – An Amazon EC2 security group configured to allow inbound traffic on port 80. This resource lets HTTP traffic from the internet reach the load balancer. By default, traffic isn't allowed on other ports.

  • Auto Scaling group – An Auto Scaling group configured to replace an instance if it is terminated or becomes unavailable.

  • Amazon S3 bucket – A storage location for your source code, logs, and other artifacts that are created when you use Elastic Beanstalk.

  • Amazon CloudWatch alarms – Two CloudWatch alarms that monitor the load on the instances in your environment and that are triggered if the load is too high or too low. When an alarm is triggered, your Auto Scaling group scales up or down in response.

  • AWS CloudFormation stack – Elastic Beanstalk uses AWS CloudFormation to launch the resources in your environment and propagate configuration changes. The resources are defined in a template that you can view in the AWS CloudFormation console.

  • Domain name – A domain name that routes to your web app in the form

All of these resources are managed by Elastic Beanstalk. When you terminate your environment, Elastic Beanstalk terminates all the resources that it contains.


The Amazon S3 bucket that Elastic Beanstalk creates is shared between environments and is not deleted during environment termination. For more information, see Using Elastic Beanstalk with Amazon S3.

Install Symfony and Generate a Website

Composer can install Symfony and create a working project with one command:

~$ composer create-project symfony/website-skeleton eb-symfony Installing symfony/website-skeleton (v4.3.99) - Installing symfony/website-skeleton (v4.3.99): Downloading (100%) Created project in eb-symfony Loading composer repositories with package information Updating dependencies (including require-dev) Package operations: 1 install, 0 updates, 0 removals - Installing symfony/flex (v1.4.5): Downloading (100%) Symfony operations: 1 recipe (539d006017ad5ef71beab4a2e2870e9a) - Configuring symfony/flex (>=1.0): From Loading composer repositories with package information Updating dependencies (including require-dev) Restricting packages listed in "symfony/symfony" to "4.3.*" Package operations: 103 installs, 0 updates, 0 removals - Installing ocramius/package-versions (1.4.0): Loading from cache ...

Composer installs Symfony and its dependencies, and generates a default project.

If you run into any issues installing Symfony, go to the installation topic in the official documentation:

Deploy Your Application

Go to the project directory.

~$ cd eb-symfony

Create a source bundle containing the files created by Composer. The following command creates a source bundle named It excludes files in the vendor folder, which take up a lot of space and are not necessary for deploying your application to Elastic Beanstalk.

eb-symfony$ zip ../ -r * .[^.]* -x "vendor/*"

Upload the source bundle to Elastic Beanstalk to deploy Symfony to your environment.

To deploy a source bundle

  1. Open the Elastic Beanstalk console.

  2. Navigate to the management page for your environment.

  3. Choose Upload and Deploy.

  4. Use the on-screen dialog box to upload the source bundle.

  5. Choose Deploy.

  6. When the deployment completes, choose the site URL to open your website in a new tab.


To optimize the source bundle further, initialize a Git repository and use the git archive command to create the source bundle. The default Symfony project includes a .gitignore file that tells Git to exclude the vendor folder and other files that are not required for deployment.

Configure Composer Settings

When the deployment completes, click the URL to open your Symfony application in the browser:

What's this? By default, Elastic Beanstalk serves the root of your project at the root path of the web site. In this case, though, the default page (app.php) is one level down in the web folder. You can verify this by adding /public to the URL. For example,

To serve the Symfony application at the root path, use the Elastic Beanstalk console to configure the document root for the web site.

To configure your web site's document root

  1. Open the Elastic Beanstalk console.

  2. Navigate to the management page for your environment.

  3. Choose Configuration.

  4. In the Software configuration category, choose Modify.

  5. For Document root, enter /public.

  6. Choose Apply.

  7. When the update is complete, click the URL to reopen your site in the browser.


When you finish working with Elastic Beanstalk, you can terminate your environment. Elastic Beanstalk terminates all AWS resources associated with your environment, such as Amazon EC2 instances, database instances, load balancers, security groups, and alarms.

To terminate your Elastic Beanstalk environment

  1. Open the Elastic Beanstalk console.

  2. Navigate to the management page for your environment.

  3. Choose Actions, and then choose Terminate Environment.

  4. Use the on-screen dialog box to confirm environment termination.

With Elastic Beanstalk, you can easily create a new environment for your application at any time.

Next Steps

For more information about Symfony, see What is Symfony? at

As you continue to develop your application, you'll probably want a way to manage environments and deploy your application without manually creating a .zip file and uploading it to the Elastic Beanstalk console. The Elastic Beanstalk Command Line Interface (EB CLI) provides easy-to-use commands for creating, configuring, and deploying applications to Elastic Beanstalk environments from the command line.

In this tutorial, you used the Elastic Beanstalk console to configure composer options. To make this configuration part of your application source, you can use a configuration file like the following.

Example .ebextensions/composer.config

option_settings: aws:elasticbeanstalk:container:php:phpini: document_root: /public

For more information, see Advanced Environment Customization with Configuration Files (.ebextensions).

Symfony uses its own configuration files to configure database connections. For instructions on connecting to a database with Symfony, see Connecting to a Database with Symfony.

Finally, if you plan on using your application in a production environment, you will want to configure a custom domain name for your environment and enable HTTPS for secure connections.