AWS Elastic Beanstalk and Composer

后端 未结 4 1386
既然无缘
既然无缘 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.

    0 讨论(0)
  • 2020-12-16 03:10

    Composer is already installed default in Beanstalk's PHP AMI.

    Also consider that container_commands are ran through '/var/app/ondeck' and not on current. Try something like this:

    container_commands:
      01-install-packages:
        command: "composer.phar install -d /var/app/ondeck/www"
    
    0 讨论(0)
  • 2020-12-16 03:19

    Just a note, most of the PHP containers that AWS is using in Elastic Beanstalk are auto deploying by running composer.phar install now. You should be able to skip this step if you don't have a "vendors" folder present. If you want to run it manually, the above methods should work, but you should only need something like @kewubenduben mentioned.

    If you are trying to access a private remote repository, check out the Q and A here: AWS Elastic Beanstalk using PHP with Private Composer Repositories , shameless plug.

    0 讨论(0)
  • 2020-12-16 03:20

    Went with the suggestion provided by @tbjes and moved composer related files outside of my document root to the project root and after a quick test all appears to be working out of the box without having to run composer via .ebxtenstions config files.

    0 讨论(0)
提交回复
热议问题