Reduce Composer Issues on Elastic Beanstalk
During the past couple of months, we’ve had a few reports from customers where they have experienced PHP application deployment failures on AWS Elastic Beanstalk related to parsing exceptions being thrown by Composer. In case you have recently run into the issue yourself, we would like to briefly describe why it is happening and how you can circumvent the issue.
The issue occurs when a project or its dependencies expresses its requirements using newer Composer syntax features like the carat (
^) operator. For users of the AWS SDK for PHP, the error looks something like this:
[RuntimeException] Could not load package aws/aws-sdk-php in http://packagist.org: [UnexpectedValueException] Could not parse version constraint ^5.3: Invalid version string "^5.3"
We also observed the issue with some versions of the Laravel framework and a few other libraries. The issue comes up when you are using older Elastic Beanstalk stacks with your applications. The older stacks have an old version of Composer included on the underlying Amazon Machine Image (AMI) that does not support some of the latest Composer features like the carat (
^) and new OR (
There are 3 different ways to solve this issue.
- Upgrade your application to use the latest Elastic Beanstalk solution stack. The latest solution stacks for PHP have a more recent version of Composer that supports the new syntax features.
- Use Elastic Beanstalk configuration files (
.ebextension). You can create a file ending in
.ebextensiondirectory that allows you to perform a Compose
self-updatecommand before installing your dependencies. For example, name the file
01composer.configand add the following configuration:
commands: 01updateComposer: command: export COMPOSER_HOME=/root && /usr/bin/composer.phar self-update option_settings: - namespace: aws:elasticbeanstalk:application:environment option_name: COMPOSER_HOME value: /root
- Install your dependencies locally. One way to avoid issues with Composer during deployment is to bypass the whole Composer workflow entirely by creating deployments of your application with the dependencies pre-installed.
We hope that this short blog post will be helpful if you happen to run into this issue. If this article does not solve your problem or you are running into other issues, please contact AWS Support or ask for help on the Elastic Beanstalk forum.