AWS Elastic Beanstalk and Composer

后端 未结 4 1385
既然无缘
既然无缘 2020-12-16 02:22

I have an application with Composer dependencies which I want to deploy to an Elastic Beanstalk container. However my composer.json file is not in the project root folder.

4条回答
  •  囚心锁ツ
    2020-12-16 03:04

    The syntax has changed slightly as of 2019. To run composer automatically when you deploy via elastic beanstalk, add the following file (01composer.config) to a folder called ".ebextensions" in the root of your repository / code project :

    The contents of that file should be a follows, for a simple but effective run of composer each time your code is deployed :

    commands:
       composer_update:
          command: export COMPOSER_HOME=/root && /usr/bin/composer.phar self-update
    
    option_settings:
       - namespace: aws:elasticbeanstalk:application:environment
         option_name: COMPOSER_HOME
         value: /root
    
    container_commands:
      01-install_dependencies:
           command: "php /usr/bin/composer.phar install"
           cwd: "/var/app/ondeck"
      
      02-optimize:
          command: "php /usr/bin/composer.phar dump-autoload --optimize"
          cwd: "/var/app/ondeck"
    

    Spacing is important. Indent as the code above (copied from a working example, June 2020). The number 01 at the beginning of the file name indicates the running order of these command files. You can change these numbers / order based on your setup. I always put composer 1st in the list.

    EDIT: FYI composer install doesn't install composer! It installs the packages within composer. Composer must already be installed, which it should be by default as part of AWS's PHP AMI.

提交回复
热议问题