在 Elastic Beanstalk Composer 更新问题中使用 MongoDB 的 Laravel

Posted

技术标签:

【中文标题】在 Elastic Beanstalk Composer 更新问题中使用 MongoDB 的 Laravel【英文标题】:Laravel with MongoDB in Elastic Beanstalk Composer Update Issue 【发布时间】:2021-12-20 22:02:00 【问题描述】:

我正在尝试在 AWS Elastic Beanstalk 中为 php 启用 MongoDB ext 部署 Laravel 应用程序。

我在.ebextensions中有如下配置

文件:01_install_mongo.config

packages:
  rpm:
    php-pear: []
    php-devel: []
    gcc: []
files:
    "/etc/php.d/99mongo.ini":
        mode: "000755"
        owner: root
        group: root
        content: |
            extension=mongo.so
commands:
    install_mongo_driver_command:
        command: sudo pecl install mongodb
        ignoreErrors: true

我什至尝试过command: sudo pecl install mongodb-1.10

文件:02_update_composer.config

commands:
  01updateComposer:
    command: export COMPOSER_HOME=/root && /usr/bin/composer.phar self-update 2.1.11

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

但是构建总是失败并出现以下错误:

> @php artisan package:discover --ansi
PHP Warning:  PHP Startup: Unable to load dynamic library 'mongo.so' (tried: /usr/lib64/php/modules/mongo.so (/usr/lib64/php/modules/mongo.so: cannot open shared object file: No such file or directory), /usr/lib64/php/modules/mongo.so.so (/usr/lib64/php/modules/mongo.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
Script @php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 1

知道可能是什么问题吗?

编辑

cfn-init.log

021-11-07 18:36:22,532 [INFO] -----------------------Starting build-----------------------
2021-11-07 18:36:22,539 [INFO] Running configSets: Infra-EmbeddedPreBuild
2021-11-07 18:36:22,542 [INFO] Running configSet Infra-EmbeddedPreBuild
2021-11-07 18:36:22,545 [INFO] Running config prebuild_0_test_app
2021-11-07 18:36:22,545 [INFO] All RPMs were already installed
2021-11-07 18:37:20,444 [INFO] Command install_mongo_driver_command succeeded
2021-11-07 18:37:20,449 [INFO] Running config prebuild_1_test_app
2021-11-07 18:37:23,357 [INFO] Command 01_update_composer succeeded
2021-11-07 18:37:23,361 [INFO] Running config prebuild_2_test_app
2021-11-07 18:37:23,363 [INFO] ConfigSets completed
2021-11-07 18:37:23,363 [INFO] -----------------------Build complete-----------------------
2021-11-07 18:42:59,394 [INFO] -----------------------Starting build-----------------------
2021-11-07 18:42:59,401 [INFO] Running configSets: Infra-EmbeddedPreBuild
2021-11-07 18:42:59,404 [INFO] Running configSet Infra-EmbeddedPreBuild
2021-11-07 18:42:59,407 [INFO] Running config prebuild_0_test_app
2021-11-07 18:42:59,407 [INFO] All RPMs were already installed
2021-11-07 18:42:59,773 [ERROR] Command install_mongo_driver_command (sudo pecl install mongodb) failed
2021-11-07 18:42:59,773 [INFO] ignoreErrors set to true, continuing build
2021-11-07 18:42:59,778 [INFO] Running config prebuild_1_test_app
2021-11-07 18:43:02,716 [INFO] Command 01updateComposer succeeded
2021-11-07 18:43:02,721 [INFO] Running config prebuild_2_test_app
2021-11-07 18:43:02,725 [INFO] ConfigSets completed
2021-11-07 18:43:02,726 [INFO] -----------------------Build complete-----------------------
2

ignoreErrors: false 时,该命令会引发此异常。


Traceback (most recent call last):
  File "/opt/aws/bin/cfn-init", line 176, in <module>
    worklog.build(metadata, configSets)
  File "/usr/lib/python3.7/site-packages/cfnbootstrap/construction.py", line 135, in build
    Contractor(metadata).build(configSets, self)
  File "/usr/lib/python3.7/site-packages/cfnbootstrap/construction.py", line 561, in build
    self.run_config(config, worklog)
  File "/usr/lib/python3.7/site-packages/cfnbootstrap/construction.py", line 573, in run_config
    CloudFormationCarpenter(config, self._auth_config).build(worklog)
  File "/usr/lib/python3.7/site-packages/cfnbootstrap/construction.py", line 273, in build
    self._config.commands)
  File "/usr/lib/python3.7/site-packages/cfnbootstrap/command_tool.py", line 127, in apply
    raise ToolError(u"Command %s failed" % name)


【问题讨论】:

这能回答你的问题吗? Installing php mongo driver on AWS Elastic Beanstalk 尝试删除`命令中的sudo:sudo pecl install mongodb` @N69S 对于您的第一条评论:我之前尝试过,失败了 @N69S 第二个,还是不行。 在mongo.ini的内容部分中extension=mongo.so不应该是extension=mongodb.so 【参考方案1】:

我通过将平台降级到 在 64 位 Amazon Linux 2/3.3.5 上运行的 PHP 7.4

解决了这个问题

任何人都可以使用的完整配置:

https://github.com/stescacom/elastic_beanstalk_laravel_mongo_config

【讨论】:

以上是关于在 Elastic Beanstalk Composer 更新问题中使用 MongoDB 的 Laravel的主要内容,如果未能解决你的问题,请参考以下文章

text 在Elastic Beanstalk上安装telegraf代理

elastic-beanstalk http请求超时

如何在 elastic-beanstalk 中应用 ruby​​ 版本补丁

如何在 AWS elastic-beanstalk 中更改我的 python 版本

Elastic Beanstalk 在启动脚本时失败

如何在 aws elastic beanstalk 环境实例启动上运行 shell 脚本