Wednesday, January 27, 2016

Solution for [RuntimeException] The HOME or COMPOSER_HOME environment variable must be set for composer to run correctly - AWS Elastic beanstalk

Recently we got this error while we deploying our PHP Symfony2 application to AWS via elastic beanstalk environment.

Root cause for this issue

  • Composer have made a change in which they have deprecated COMPOSER_HOME
Solution 1:

The quick fix is to COMPOSER_HOME to HOME.

commands:
  01_update_composer:
    command: export HOME=/root && /usr/bin/composer.phar self-update

option_settings:
  - namespace: aws:elasticbeanstalk:application:environment
    option_name: HOME
    value: /root


Solution 2: 

Another option on a new instance is to lock the composer version.

Here is an example ebextension:

commands:
  01_update_composer:
    command: export HOME=/root && export COMPOSER_HOME=/root && /usr/bin/composer.phar self-update 1.0.0-alpha11

option_settings:
  - namespace: aws:elasticbeanstalk:application:environment
    option_name: COMPOSER_HOME
    value: /root
  - namespace: aws:elasticbeanstalk:application:environment
    option_name: HOME
    value: /root