AWS Elastic Beanstalk
Developer Guide (API Version 2010-12-01)
« 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.Did this page help you?  Yes | No |  Tell us about it...

Configuring PHP Containers with AWS Elastic Beanstalk

You can fine-tune the behavior of your Amazon EC2 instances by using a configuration file to configure your container settings. For instructions on customizing and configuring a PHP container, see Customizing and Configuring a PHP Environment. For a list of container options, see PHP Container Options.

The Container/PHP Options panel also lets you fine-tune the behavior of your Amazon EC2 instances and enable or disable Amazon S3 log rotation. You can edit the AWS Elastic Beanstalk environment's Amazon EC2 instance configuration with the Container tab using the AWS Management Console.

AWS Management Console

The Container/PHP Options panel lets you fine-tune the behavior of your Amazon EC2 instances and enable or disable Amazon S3 log rotation. You can edit the AWS Elastic Beanstalk environment's Amazon EC2 instance configuration with the Container tab using the AWS Management Console.

To access the Container panel for your AWS Elastic Beanstalk application

  1. Open the AWS Elastic Beanstalk console at https://console.aws.amazon.com/elasticbeanstalk/.

  2. Select your application from the drop-down list.

  3. Below the application selection drop-down list, click the Actions drop-down list for your application environment in the application's Environments list and select Edit/Load Configuration.

  4. In the Edit Configuration window, click the Container tab.

Container Options

On the Container tab, you can specify the following options:

  • Document Root — Enables you to specify the child directory of your project that is treated as the public-facing web root. If your root document is stored in your project directory, leave this set to "/". If your root document is inside a child directory (e.g., <project>/public), set this value to match the child directory. Values should begin with a "/" character, and may NOT begin with a "." character. (This value is written to the http-vhosts.conf file.)

  • Memory Limit — Specifies the amount of memory allocated to the PHP environment. (This value is written to the php.ini file.)

  • Zlib Output Compression — Specifies whether PHP should use compression for output. (This value is written to the php.ini file.)

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

  • Allow URL Fopen — Specifies whether the PHP's file functions are allowed to retrieve data from remote locations, such as websites or FTP servers. (This value is written to the php.ini file.)

  • Display Errors —Specifies whether error messages should be part of the output. (This value is written to the php.ini file.)

  • Max Execution Time — Sets the maximum time, in seconds, a script is allowed to run before it is terminated by the environment. This helps prevent poorly written scripts from tying up the server.

  • Composer Options — Sets custom options to use when installing dependencies using Composer through composer.phar install. (This value is written to the php.ini file.) For more information including available options, go to http://getcomposer.org/doc/03-cli.md#install.

Environment Properties

The Environment Properties section of the Container tab on the Edit Configuration window 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.

You can use this window to configure the following environment configuration settings:

  • Specify AWS credentials using the AWS_ACCESS_KEY_ID and AWS_SECRET_KEY boxes.

    Note

    For non-legacy containers, you can use instance profiles so that your application can use temporary security credentials to access AWS resources. To learn more, see Granting Permissions to Users and Services Using IAM Roles.

  • Specify up to five additional environment configuration settings by entering them in the PARAM boxes.

    Note

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

Accessing Environment Configuration Settings

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

Note

The get_cfg_var function is also supported.

You might have a code snippet that looks similar to the following to access the keys and parameters:

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

CLI

To edit an application's environment configuration settings

  • Update an application's environment configuration settings.

    PROMPT> elastic-beanstalk-update-environment -e MySampleAppEnv -f "Options.txt"

Options.txt

[
  {"Namespace": "aws:elasticbeanstalk:container:php:phpini",
   "OptionName": "document_root",
   "Value": "/"},
   {"Namespace": "aws:elasticbeanstalk:container:php:phpini",
   "OptionName": "memory_limit",
   "Value": "128M"},
   {"Namespace": "aws:elasticbeanstalk:container:php:phpini",
   "OptionName": "zlib.output_compression",
   "Value": "false"},
   {"Namespace": "aws:elasticbeanstalk:container:php:phpini",
   "OptionName": "allow_url_fopen",
   "Value": "true"},
   {"Namespace": "aws:elasticbeanstalk:container:php:phpini",
   "OptionName": "display_errors",
   "Value": "Off"},
   {"Namespace": "aws:elasticbeanstalk:container:php:phpini",
   "OptionName": "max_execution_time",
   "Value": "60"},
   {"Namespace": "aws:elasticbeanstalk:container:php:phpini",
   "OptionName": "composer_options",
   "Value": "vendor/package"},
   {"Namespace": "aws:elasticbeanstalk:application:environment",
   "OptionName": "AWS_ACCESS_KEY_ID",
   "Value": "AKIAIOSFODNN7EXAMPLE"},
   {"Namespace": "aws:elasticbeanstalk:application:environment",
   "OptionName": "AWS_SECRET_KEY",
   "Value": "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"},
   {"Namespace": "aws:elasticbeanstalk:application:environment",
   "OptionName": "myvar",
   "Value": "somevalue"},
   {"Namespace": "aws:elasticbeanstalk:hostmanager",
   "OptionName": "LogPublicationControl",
   "Value": "false"}
]

API

To edit an application's environment configuration settings

  • Call UpdateEnvironment with the following parameters:

    • EnvironmentName = SampleAppEnv

    • OptionSettings.member.1.Namespace = aws:elasticbeanstalk:container:php:phpini

    • OptionSettings.member.1.OptionName = document_root

    • OptionSettings.member.1.Value = /

    • OptionSettings.member.2.Namespace = aws:elasticbeanstalk:container:php:phpini

    • OptionSettings.member.2.OptionName = memory_limit

    • OptionSettings.member.2.Value = 128M

    • OptionSettings.member.3.Namespace = aws:elasticbeanstalk:container:php:phpini

    • OptionSettings.member.3.OptionName = zlib.output_compression

    • OptionSettings.member.3.Value = false

    • OptionSettings.member.4.Namespace = aws:elasticbeanstalk:container:php:phpini

    • OptionSettings.member.4.OptionName = allow_url_fopen

    • OptionSettings.member.4.Value = true

    • OptionSettings.member.5.Namespace = aws:elasticbeanstalk:container:php:phpini

    • OptionSettings.member.5.OptionName = display_errors

    • OptionSettings.member.5.Value = Off

    • OptionSettings.member.6.Namespace = aws:elasticbeanstalk:container:php:phpini

    • OptionSettings.member.6.OptionName = max_execution_time

    • OptionSettings.member.6.Value = 60

    • OptionSettings.member.7.Namespace = aws:elasticbeanstalk:container:php:phpini

    • OptionSettings.member.7.OptionName = composer_options

    • OptionSettings.member.7.Value = vendor/package

    • OptionSettings.member.8.Namespace = aws:elasticbeanstalk:application:environment

    • OptionSettings.member.8.OptionName = AWS_ACCESS_KEY_ID

    • OptionSettings.member.8.Value = AKIAIOSFODNN7EXAMPLE

    • OptionSettings.member.9.Namespace = aws:elasticbeanstalk:application:environment

    • OptionSettings.member.9.OptionName = AWS_SECRET_KEY

    • OptionSettings.member.9.Value = wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY

    • OptionSettings.member.10.Namespace = aws:elasticbeanstalk:application:environment

    • OptionSettings.member.10.OptionName = myvar

    • OptionSettings.member.10.Value = somevalue

    • OptionSettings.member.11.Namespace = aws:elasticbeanstalk:hostmanager

    • OptionSettings.member.11.OptionName = LogPublicationControl

    • OptionSettings.member.11.Value = false

    Example

    https://elasticbeanstalk.us-east-1.amazon.com/?EnvironmentName=SampleAppEnv
    &OptionSettings.member.1.Namespace=aws%3Aelasticbeanstalk%3Acontainer%3Aphp%3Aphpini
    &OptionSettings.member.1.OptionName=document_root
    &OptionSettings.member.1.Value=/
    &OptionSettings.member.2.Namespace=aws%3Aelasticbeanstalk%3Acontainer%3Aphp%3Aphpini
    &OptionSettings.member.2.OptionName=memory_limit
    &OptionSettings.member.2.Value=128M
    &OptionSettings.member.3.Namespace=aws%3Aelasticbeanstalk%3Acontainer%3Aphp%3Aphpini
    &OptionSettings.member.3.OptionName=zlib.output_compression
    &OptionSettings.member.3.Value=false
    &OptionSettings.member.4.Namespace=aws%3Aelasticbeanstalk%3Acontainer%3Aphp%3Aphpini
    &OptionSettings.member.4.OptionName=allow_url_fopen
    &OptionSettings.member.4.Value=true
    &OptionSettings.member.5.Namespace=aws%3Aelasticbeanstalk%3Acontainer%3Aphp%3Aphpini
    &OptionSettings.member.5.OptionName=display_errors
    &OptionSettings.member.5.Value=Off
    &OptionSettings.member.6.Namespace=aws%3Aelasticbeanstalk%3Acontainer%3Aphp%3Aphpini
    &OptionSettings.member.6.OptionName=max_execution_time
    &OptionSettings.member.6.Value=60
    &OptionSettings.member.7.Namespace=aws%3Aelasticbeanstalk%3Acontainer%3Aphp%3Aphpini
    &OptionSettings.member.7.OptionName=composer_options
    &OptionSettings.member.7.Value=vendor/package
    &OptionSettings.member.8.Namespace=aws%3Aelasticbeanstalk%3Aapplication%3Aenvironment
    &OptionSettings.member.8.OptionName=AWS_ACCESS_KEY_ID
    &OptionSettings.member.8.Value=AKIAIOSFODNN7EXAMPLE
    &OptionSettings.member.9.Namespace=aws%3Aelasticbeanstalk%3Aapplication%3Aenvironment
    &OptionSettings.member.9.OptionName=AWS_SECRET_KEY
    &OptionSettings.member.9.Value=wJalrXUtnFEMI%2FK7MDENG%2FbPxRfiCYEXAMPLEKEY
    &OptionSettings.member.10.Namespace=aws%3Aelasticbeanstalk%3Aapplication%3Aenvironment
    &OptionSettings.member.10.OptionName=myvar
    &OptionSettings.member.10.Value=somevalue
    &OptionSettings.member.11.Namespace=aws%3Aelasticbeanstalk%3Ahostmanager
    &OptionSettings.member.11.OptionName=LogPublicationControl
    &OptionSettings.member.11.Value=false
    &Operation=UpdateEnvironment
    &AuthParams