AWS Elastic Beanstalk
Developer Guide

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 PHP in the AWS Elastic Beanstalk Platforms document.

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

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 configure your PHP environment in the Elastic Beanstalk console

  1. Open the Elastic Beanstalk console.

  2. Navigate to the management page for your environment.

  3. Choose Configuration.

  4. On the Software configuration card, choose Modify.

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.

$endpoint = $_SERVER['API_ENDPOINT'];

See Environment Properties and Other Software Settings for more information.

The aws:elasticbeanstalk:container:php:phpini Namespace

You can use a configuration file to set configuration options and perform other instance configuration tasks during deployments. Configuration options can be defined by the Elastic Beanstalk service or the platform that you use and are organized into namespaces.

The PHP platform defines options in the aws:elasticbeanstalk:container:php:phpini namespace, including one 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:

Example .ebextensions/php-settings.config

option_settings: aws:elasticbeanstalk:container:php:phpini: 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

Elastic Beanstalk provides many configuration options for customizing your environment. In addition to configuration files, you can also set configuration options using the console, saved configurations, the EB CLI, or the AWS CLI. See Configuration Options for more information.