AWS Elastic Beanstalk
Developer Guide (API Version 2010-12-01)

Deploying a CakePHP 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 CakePHP framework.


This example uses Amazon RDSs, and you may be charged for its usage. For more information about pricing, go to Amazon Relational Database Service (RDS) Pricing. If you are a new customer, you can make use of the AWS Free Usage Tier. For details, go to AWS Free Usage Tier.

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 Install the EB Command Line Interface (CLI).

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 CakePHP Development Environment

Set up CakePHP and create the project structure. The following steps walk you through setting up CakePHP on a Linux operating system. For more information, go to

To set up your PHP development environment on your local computer

  1. Download the latest release of CakePHP. This can be done using the .zip file available from GitHub.

    mkdir ~/cakephp_example
    cd ~/cakephp_example
    unzip && rm
    mv cakephp-2.2.4/* . && rm -rf cakephp-2.2.4
  2. Initialize the Git repository.

    git init 
  3. Copy the database settings over.

    cp app/Config/database.php.default app/Config/database.php
  4. CakePHP excludes app/Config by default from being committed to a repository. (The .gitignore file that comes with CakePHP also excludes app/tmp by default from being committed to a repository.) When deploying to Elastic Beanstalk, we need the database to be configured so that it reads database settings from environment variables. So we need to make sure we do not exclude our database settings. Update the .gitignore file so that it does not exclude our database settings.

    cat > .gitignore <<EOT

Step 3: Configure Elastic Beanstalk

The following instructions use the Elastic Beanstalk command line interface (EB CLI) to configure an Elastic Beanstalk application repository in your local project directory.

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 cakephpapp.

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


    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 the sample application with your own application. In this step, we'll update the sample application with a simple "Hello World" CakePHP application.

To update the sample application

  1. On your local computer, modify the app/Config/database.php to include RDS database settings. You'll need to add a block of code above the `class DATABASE_CONFIG {` line that defines constant values for RDS configurations. You then need to modify the public $default value to use the constants.

    if (!defined('RDS_HOSTNAME')) {
      define('RDS_DB_NAME', $_SERVER['RDS_DB_NAME']);
      public $default = array(
        'datasource' => 'Database/Mysql',
        'persistent' => false,
        'host' => RDS_HOSTNAME,
        'login' => RDS_USERNAME,
        'password' => RDS_PASSWORD,
        'database' => RDS_DB_NAME,
        'prefix' => '',
       //'encoding' => 'utf8',
      public $test = array(
        'datasource' => 'Database/Mysql',
        'persistent' => false,
        'host' => 'localhost',
        'login' => 'user',
        'password' => 'password',
        'database' => 'test_database_name',
        'prefix' => '',
        //'encoding' => 'utf8',
  2. Add your files to your local Git repository, and then commit your change.

    git add -A && git commit -m "eb config"


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

  3. 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 Using the EB CLI.

You can access the logs for your EC2 instances running your application. For instructions on accessing your logs, see Instance 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.