英文:
Why Can't I Run Composer Install on Deploy in AWS Elastic Beanstalk?
问题
看起来我在尝试在 EB 中部署我的应用程序时遇到了一些问题。我得到了这个错误:
> 实例部署:您没有在源捆绑包中包含 'composer.json' 文件。部署未安装 Composer 依赖项。
我正在按照这里1和这里2的文档进行操作。以下是文件结构的一个视图:
.
|____Buildfile
|____composer.json
|____composer.lock
|____index.php
|____api
| |____v1
| | |____index.php
我的 Buildfile:
01_composer_install: composer install
任何帮助或指导将不胜感激。
更新:
我尝试添加 .platform 钩子,但没有成功。出现相同的错误。
新的树结构:
.
|____.platform
| |____hooks
| | |____predeploy
| | | |____01_composer_install.sh
|____composer.json
|____composer.lock
|____index.php
|____api
| |____v1
| | |____index.php
01_composer_install.sh
内容:
#!/bin/bash
composer install
英文:
Apparently I'm missing something when trying to deploy my application in EB. I'm getting this error:
> Instance deployment: You didn't include a 'composer.json' file in your source bundle. The deployment didn't install Composer dependencies.
I'm following the docs here and here. Here's a view of the file structure:
.
|____Buildfile
|____composer.json
|____composer.lock
|____index.php
|____api
| |____v1
| | |____index.php
My Buildfile:
01_composer_install: composer install
Any help or guidance would be much appreciated.
UPDATE:
I tried adding the .platform hooks with no success. Same error.
New tree structure:
.
|____.platform
| |____hooks
| | |____predeploy
| | | |____01_composer_install.sh
|____composer.json
|____composer.lock
|____index.php
|____api
| |____v1
| | |____index.php
01_composer_install.sh
contents:
#!/bin/bash
composer install
答案1
得分: 3
您不需要手动运行 composer install
。当存在一个 composer.json
文件时,Elastic Beanstalk 会自动运行 composer.phar install
来为您安装依赖项。并且,当 Elastic Beanstalk 在实例上找到一个 vendor 文件夹时,它会忽略 composer.json
文件(即使它存在)。然后,您的应用程序将使用来自 vendor 文件夹的依赖项。
此外,如果您想在通过 composer.phar
安装依赖项时设置自定义选项,您可以在 .ebextensions
配置文件的 aws:elasticbeanstalk:container:php:phpini
命名空间中定义 composer_options
。例如:
.ebextensions/php-settings.config
option_settings:
aws:elasticbeanstalk:container:php:phpini:
document_root: /public
memory_limit: 128M
zlib.output_compression: "Off"
allow_url_fopen: "On"
display_errors: "Off"
max_execution_time: 60
composer_options: vendor/package
来源:
关于错误,由于您尝试使用构建文件和钩子执行 composer install
,它可能不在应用程序源代码的根目录下运行,因此找不到 composer.json 文件,所以您可能需要指定 composer.json 的绝对路径来运行 composer install,尽管我对此部分不太确定。
希望这有所帮助。
英文:
You don't need to run composer install
manually. When a composer.json
file is present, Elastic Beanstalk runs composer.phar install
to install dependencies for you. And, when Elastic Beanstalk finds a vendor folder on the instance, it ignores the composer.json
file (even if it exists). Your application then uses dependencies from the vendor folder.
Source: Installing your application's dependencies
Further, in case you want to sets custom options to use when installing dependencies using Composer through composer.phar
install, you can defines composer_options
in the aws:elasticbeanstalk:container:php:phpini
namespace in the configuration file of .ebextensions
. For example:-
.ebextensions/php-settings.config
option_settings:
aws:elasticbeanstalk:container:php:phpini:
document_root: /public
memory_limit: 128M
zlib.output_compression: "Off"
allow_url_fopen: "On"
display_errors: "Off"
max_execution_time: 60
composer_options: vendor/package
sources:
Regarding the error, as you are trying to execute composer install
with buildfile and hooks, it might not be running at the root of your application source code so it couldn't find the composer.json file, so you might need to specify the absolute path of your composer.json with composer install, although I'm not very much sure on this part.
I hope this helps.
答案2
得分: 1
你上传的 zip 文件很可能(假设你已经上传为 zip 文件)在顶层有一个目录。也就是说,如果你查看 zip 结构,它将是
MyProject
|
--- composer.json
请确保如果你从文件资源管理器中压缩文件,选择的是文件夹中的文件,而不是文件夹本身。我经常看到这种情况发生。
英文:
Most likely your zip file (assuming you uploaded as zip) has a directory on top. That is, if you look at the zip structure it will be
MyProject
|
--- composer.json
Make sure that if you zip from File Explorer, you select files in the folder and not the folder itself. I see it happening all the time
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论