AWS Elastic Beanstalk
Developer Guide (API Version 2010-12-01)
AWS services or capabilities described in AWS Documentation may vary by region/location. Click Getting Started with Amazon AWS to see specific differences applicable to the China (Beijing) Region.

Using the AWS Elastic Beanstalk PHP Platform

AWS Elastic Beanstalk supports a number of platforms for different versions of the PHP programming language. These platforms support PHP web applications that can run alone or under Composer. Learn more at the Pre-Configured Platforms topic.

Elastic Beanstalk provides configuration options that you can use to customize the software that runs on the EC2 instances in your Elastic Beanstalk environment. You can configure environment variables needed by your application, enable log rotation to Amazon S3, and set common PHP initialization settings.

Platform-specific configuration options are available in the AWS Management Console for modifying the configuration of a running environment. To avoid losing your environment's configuration when you terminate it, you can use saved configurations to save your settings and later apply them to another environment.

To save settings in your source code, you can include configuration files. Settings in configuration files are applied every time you create an environment or deploy your application. You can also use configuration files to install packages, run scripts, and perform other instance customization operations during deployments.

If you use Composer, you can include a composer.json file in your source bundle to install packages during deployment.

For advanced PHP configuration and PHP settings that are not provided as configuration options, you can use configuration files to provide an INI file that can extend and override the default settings applied by Elastic Beanstalk, or install additional extensions.

Settings applied in the AWS Management Console override the same settings in configuration files, if they exist. This lets you have default settings in configuration files, and override them with environment specific settings in the console. For more information about precedence, and other methods of changing settings, see Configuration Options.

Configuring your PHP Environment in the AWS Management Console

You can use the AWS Management Console to enable log rotation to Amazon S3, configure variables that your application can read from the environment, and change PHP settings.

To access the configuration options for your PHP environment

  1. Open the Elastic Beanstalk console.

  2. Navigate to the management page for your environment.

  3. Choose Configuration.

  4. In the Software Configuration section, choose the settings icon ( Edit ).

PHP Settings

  • Document root – The folder that contains your site's default page. If your welcome page is not at the root of your source bundle, specify the folder that contains it relative to the root path. For example, /public if the welcome page is in a folder named public.

  • Memory limit – The maximum amount of memory that a script is allowed to allocate. For example, 512M.

  • Zlib output compression – Set to On to compress responses.

  • Allow URL fopen – Set to Off to prevent scripts from downloading files from remote locations.

  • Display errors – Set to On to show internal error messages for debugging.

  • Max execution time – The maximum time in seconds that a script is allowed to run before the environment terminates it.

Log Options

The Log Options section has two settings:

  • Instance profile– Specifies the instance profile that has permission to access the Amazon S3 bucket associated with your application.

  • Enable log file rotation to Amazon S3–Specifies whether log files for your application's Amazon EC2 instances should be copied to your Amazon S3 bucket associated with your application.

Environment Properties

The Environment Properties section lets you specify environment configuration settings on the Amazon EC2 instances that are running your application. These settings are passed in as key-value pairs to the application.

Inside the PHP environment running in Elastic Beanstalk, these values are written to /etc/php.d/environment.ini and are accessible using $_SERVER or the get_cfg_var function.

The following code prints parameters from the $_SERVER object:

echo $_SERVER['PARAM1'];
echo $_SERVER['PARAM2'];
echo $_SERVER['PARAM5'];


Environment configuration settings can contain any printable ASCII character except the grave accent (`, ASCII 96) and cannot exceed 200 characters in length.

Configuration Files

You can use a configuration file to set configuration options and perform other instance configuration tasks during deployments. The PHP platform also provides a configuration option in the aws:elasticbeanstalk:container:php:phpini namespace that is not available in the AWS Management Console

Composer Options sets custom options to use when installing dependencies using Composer through composer.phar install. For more information including available options, go to

The following example configuration file shows settings for each of the options available in this namespace:

    document_root: /public
    memory_limit: 128M
    zlib.output_compression: "Off"
    allow_url_fopen: "On"
    display_errors: "Off"
    max_execution_time: 60
    composer_options: vendor/package

Composer File

Use a composer.json file in the root of your project source to use composer to install packages that your application requires.

Example composer.json

    "require": {
        "monolog/monolog": "1.0.*"

When a composer.json file is present, Elastic Beanstalk runs composer.phar install to install dependencies. You can add options to append to the command by setting the composer_options option in the aws:elasticbeanstalk:container:php:phpini namespace.

Update Composer

PHP platform configurations ship with the latest version of Composer available at the time of release. To keep Composer, PHP, and other libraries up to date, upgrade your environment whenever a platform update is available.

Between platform updates, you can use a configuration file to update Composer on the instances in your environment. You may need to update Composer if you see an error when you try to install packages with a Composer file, or if you are unable to use the latest platform version.

Example .ebextensions/composer.config

    command: export COMPOSER_HOME=/root && /usr/bin/composer.phar self-update 1.4.1

  - namespace: aws:elasticbeanstalk:application:environment
    option_name: COMPOSER_HOME
    value: /root

This configuration file configures composer to update itself to version 1.4.1. Check the Composer releases page on GitHub to find the latest version.


If you omit the version number from the composer.phar self-update command, Composer will update to the latest version available every time you deploy your source code, and when new instances are provisioned by Auto Scaling. This could cause scaling operations and deployments to fail if a version of Composer is released that is incompatible with your application.

Extending php.ini

Use a configuration file with a files block to add a .ini file to /etc/php.d/ on the instances in your environment. The main configuration file, php.ini, pulls in settings from files in this folder in alphabetical order. Many extensions are enabled by default by files in this folder.

Example .ebextensions/mongo.config

  "/etc/php.d/99mongo.ini" :
    mode: "000755"
    owner: root
    group: root
    content: |