Elastic Beanstalk
Developer Guide (API Version 2010-12-01)
Did this page help you?  Yes | No |  Tell us about it...
« PreviousNext »
View the PDF for this guide.Go to the AWS Discussion Forum for this product.Go to the Kindle Store to download this guide in Kindle format.

Deploying a Symfony2 Application to Elastic Beanstalk

This section walks you through deploying a sample application to Elastic Beanstalk using EB Command Line Interface (CLI) 3.x and Git, and then updating the application to use the Symfony2 framework.

Step 1: Set Up Your Git Repository

EB CLI is a command line interface that you can use with Git to deploy applications quickly and more easily. EB is available as part of the Elastic Beanstalk command line tools package. For instructions to install EB CLI, see Getting Set Up with EB Command Line Interface (CLI) 3.x.

Initialize your Git repository. After you run the following command, when you run eb init, EB CLI will recognize that your application is set up with Git.

git init .

Step 2: Set Up Your Symfony2 Development Environment

Set up Symfony2 and create the project structure. The following walks you through setting up Symfony2 on a Linux operating system. For more information, go to http://symfony.com/download.

To set up your PHP development environment on your local computer

  1. Download and install composer from getcomposer.org. For more information, go to http://getcomposer.org/download/.

    curl -s https://getcomposer.org/installer | php
  2. Install Symfony2 Standard Edition with Composer. Check http://symfony.com/download for the latest available version. Using the following command, composer will install the vendor libraries for you.

    php composer.phar create-project symfony/framework-standard-edition symfony2_example/ <version number>
    cd symfony2_example


    You may need to set the date.timezone in the php.ini to successfully complete installation. Also provide parameters for Composer, as needed.

  3. Initialize the Git repository.

    git init 
  4. Update the .gitignore file to ignore vendor, cache, logs, and composer.phar. These files do not need to get pushed to the remote server.

    cat > .gitignore <<EOT
  5. Generate the hello bundle.

    php app/console generate:bundle --namespace=Acme/HelloBundle --format=yml

    When prompted, accept all defaults. For more information, go to Creating Pages in Symfony2.

Next, configure Composer. Composer dependencies require that you set the HOME or COMPOSER_HOME environment variable. Also configure Composer to self-update so that you always use the latest version.

To configure Composer

  1. Create a configuration file with the extension .config (e.g., composer.config) and place it in an .ebextensions directory at the top level of your source bundle. You can have multiple configuration files in your .ebextensions directory. For information about the file format of configuration files, see Using Configuration Files.


    Configuration files should conform to YAML or JSON formatting standards. For more information, go to http://www.yaml.org/start.html or http://www.json.org, respectively.

  2. In the .config file, type the following.

        command: export COMPOSER_HOME=/root && /usr/bin/composer.phar self-update
      - namespace: aws:elasticbeanstalk:application:environment
        option_name: COMPOSER_HOME
        value: /root

Step 3: Configure Elastic Beanstalk

You use eb, a command line tool, to configure Elastic Beanstalk. If you haven't already installed eb on your local computer, do that now at the AWS Sample Code & Libraries website. If you are running eb on a Linux operating system, you will need to install Python 2.7 or 3.0.

Before you use eb, set your PATH to the location of eb. The following table shows an example for Linux/UNIX and Windows.

In Linux and UNIXIn Windows
$ export PATH=$PATH:<path to unzipped eb CLI package>/eb/linux/python2.7/

If you are using Python 3.0, the path will include python3 rather than python2.7.

C:\> set PATH=%PATH%;<path to unzipped eb CLI package>\eb\windows\

Use the init command, and Elastic Beanstalk will prompt you to enter this information. If a default value is available, and you want to use it, press Enter.

To configure Elastic Beanstalk

  1. From the directory where you created your local repository, type the following command:

    eb init
  2. When you are prompted for the Elastic Beanstalk region, type the number of the region. For information about this product's regions, go to Regions and Endpoints in the Amazon Web Services General Reference. For this example, we'll use US West (Oregon).

  3. When you are prompted for the Elastic Beanstalk application name, type the name of the application. Elastic Beanstalk generates an application name based on the current directory name if an application name has not been previously configured. In this example, we use symfony2app.

    Enter an AWS Elastic Beanstalk application name (auto-generated value is "windows"): symfony2app


    If you have a space in your application name, make sure you do not use quotation marks.

  4. Type y if Elastic Beanstalk correctly detected the correct platform you are using. Type n if not, and then specify the correct platform.

  5. When prompted, type y if you want to set up Secure Shell (SSH) to connect to your instances. Type n if you do not want to set up SSH. In this example, we will type n.

    Do you want to set up SSH for your instances?
    (y/n): n
  6. Create your running environment.

    eb create
  7. When you are prompted for the Elastic Beanstalk environment name, type the name of the environment. Elastic Beanstalk automatically creates an environment name based on your application name. If you want to accept the default, press Enter.

    Enter Environment Name
    (default is HelloWorld-env):


    If you have a space in your application name, make sure you do not have a space in your environment name.

  8. When you are prompted to provide a CNAME prefix, type the CNAME prefix you want to use. Elastic Beanstalk automatically creates a CNAME prefix based on the environment name. If you want to accept the default, press Enter.

    Enter DNS CNAME prefix
    (default is HelloWorld):

After configuring Elastic Beanstalk, you are ready to deploy a sample application.

If you want to update your Elastic Beanstalk configuration, you can use the init command again. When prompted, you can update your configuration options. If you want to keep any previous settings, press the Enter key.

To deploy a sample application

  • From the directory where you created your local repository, type the following command:

    eb deploy

    This process may take several minutes to complete. Elastic Beanstalk will provide status updates during the process. If at any time you want to stop polling for status updates, press Ctrl+C. Once the environment status is Green, Elastic Beanstalk will output a URL for the application. You can copy and paste the URL into your web browser to view the application.

Step 4: View the Application

To view the application

  • To open your application in a browser window, type the following:

    eb open

Step 5: Update the Application

After you have deployed a sample application, you can update it with your own application. In this step, we update the sample application with a simple "Hello World" Symfony2 application.

To update the sample application

  1. Add your files to your local Git repository, and then commit your change.

    git add -A && git commit -m "Initial commit"


    For information about Git commands, go to Git - Fast Version Control System.

  2. Create an application version matching your local repository and deploy to the Elastic Beanstalk environment if specified.

    eb deploy

    You can also configure Git to push from a specific branch to a specific environment. For more information, see "Using Git with EB CLI" in the topic Getting Started with EB CLI 3.x.

  3. After your environment is Green and Ready, append /web/hello/AWS to the URL of your application. The application should write out "Hello AWS!"

You can access the logs for your EC2 instances running your application. For instructions on accessing your logs, see Working with Logs.

Step 6: Clean Up

If you no longer want to run your application, you can clean up by terminating your environment and deleting your application.

Use the terminate command to terminate your environment and the delete command to delete your application.

To terminate your environment and delete the application

  • From the directory where you created your local repository, type the following command:

    eb terminate

    This process may take a few minutes. Elastic Beanstalk displays a message once the environment has been successfully terminated.


    If you attached an Amazon RDS DB instance to your environment, your Amazon RDS DB will be deleted, and you will lose your data. To save your data, create a snapshot before you delete the application. For instructions on how to create a snapshot, go to Creating a DB Snapshot in the Amazon Relational Database Service User Guide.