Updating Composer - AWS Elastic Beanstalk

Updating Composer

You may have to update Composer if you see an error when you try to install packages with a Composer file, or if you're unable to use the latest platform version. Between platform updates, you can update Composer in your environment instances through the use of configuration files in your .ebextensions folder.

You can self-update Composer with the following configuration.

commands: 01updateComposer: command: /usr/bin/composer.phar self-update 2.7.0

The following option setting sets the COMPOSER_HOME environment variable, which configures the location of the Composer cache.

option_settings: - namespace: aws:elasticbeanstalk:application:environment option_name: COMPOSER_HOME value: /home/webapp/composer-home

You can combine both of these in the same configuration file in your .ebextensions folder.

Example .ebextensions/composer.config
commands: 01updateComposer: command: /usr/bin/composer.phar self-update 2.7.0 option_settings: - namespace: aws:elasticbeanstalk:application:environment option_name: COMPOSER_HOME value: /home/webapp/composer-home
Note

Due to updates to the Composer installation in the February 22, 2024, AL2023 platform release and the February 28, 2024, AL2 platform release, the Composer self-update may fail if COMPOSER_HOME is set when the self-update executes.

The following combined commands will fail to execute: export COMPOSER_HOME=/home/webapp/composer-home && /usr/bin/composer.phar self-update 2.7.0

However, the previous example will work. In the previous example, the option setting for COMPOSER_HOME will not be passed to the 01updateComposer execution, and it will not be set when the self-update command executes.

Important

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.

For more information about the Elastic Beanstalk PHP Platforms, including the version of Composer, see PHP platform versions in the document AWS Elastic Beanstalk Platforms.