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 Supported 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
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
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,
/publicif the welcome page is in a folder named
Memory limit – The maximum amount of memory that a script is allowed to allocate. For example,
Zlib output compression – Set to
Onto compress responses.
Allow URL fopen – Set to
Offto prevent scripts from downloading files from remote locations.
Display errors – Set to
Onto 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.
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.
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
The following code prints parameters from the
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.
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 http://getcomposer.org/doc/03-cli.md#install.
The following example configuration file shows settings for each of the options available in this namespace:
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
composer.json file in the root of your project source to use
composer to install packages that your application requires.
composer.json file is present, Elastic Beanstalk runs
install to install dependencies. You can add options to append to the command by
option in the
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
files: "/etc/php.d/99mongo.ini" : mode: "000755" owner: root group: root content: | extension=mongo.so