2

我正在尝试在 Elastic Beanstalk 上部署一个 php 应用程序。除了我对 mongo 驱动程序的调用之外,一切都运行良好。

我尝试安装它遵循以下步骤(不成功):

  1. SSH 到 Elastic Beanstalk 实例。
  2. sudo yum install php-devel (用于 phpize)
  3. sudo pecl install mongo
  4. 按照说明尝试命令:sudo echo "extension=mongo.so" >> /etc/php.ini失败。错误信息是:

    -bash: /etc/php.ini: Permission denied

我会以正确的方式解决这个问题吗?

4

3 回答 3

5

You should not SSH into Elastic Beanstalk to install php-devel and mongo. Those settings will disappear when your EB environment scales in/out or server crash by accident.

Try to use Configuration File to customize your EB Environment.

Updated: add a configuration file example for PHP 5.4 on 64bit Amazon Linux 2013.09

  1. Create an .ebextensions directory in the top-level of your source bundle.
  2. Create a configuration file, /your_app/.ebextensions/01install_mongo_driver.config.

Type the following inside the configuration file 01install_mongo_driver.config to install php mongodb driver.

commands:
  install_mongo_driver_command:
    command: pecl install mongo

Because PHP 5.4 on 64bit Amazon Linux 2013.09 AMI already contained php-devel, so you won't install it manually.

于 2013-11-12T00:59:13.093 回答
5

Amazon Linux 2 上 PHP 7 上的 MongoDB 更新

files:
 "/etc/php.d/99mongo.ini" :
   mode: "000755"
    owner: root
    group: root
    content: |
      extension=mongo.so
commands:
  install_mongo_driver_command:
    command: sudo pecl7 install mongodb
    ignoreErrors: true

以上添加启用 php.ini 上的扩展并为您的 PHP 安装 mongodb。如果第二次安装,这ignore errors可以防止任何错误。(例如,如果您的服务器崩溃并且必须重新启动)。这是为了防止出现“mongodb is already installed”的错误

注意:此文件存储在:/your_app_root/.ebextensions/mongo.config

于 2020-03-11T01:17:45.003 回答
2

就今天而言,通过 AWS Beanstalk 在最新版本的 Amazon Linux 2 中安装mongodb的正确设置如下,其他一切对我来说都失败了。如果您无法解决它,请像我一样做并连接到服务器并查看日志。

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
于 2020-09-03T05:20:45.697 回答