简体   繁体   English

在 AWS Elastic Beanstalk 上安装 php mongo 驱动程序

[英]Installing php mongo driver on AWS Elastic Beanstalk

I am trying to deploy a php application on Elastic Beanstalk.我正在尝试在 Elastic Beanstalk 上部署一个 php 应用程序。 Everything is working fine except from my calls to the mongo driver.除了我打电话给 mongo 驱动程序外,一切正常。

My attempt to install it followed these steps (unsuccessfully):我尝试安装它遵循以下步骤(不成功):

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

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

Am I going about this the right way?我会以正确的方式解决这个问题吗?

You should not SSH into Elastic Beanstalk to install php-devel and mongo .您不应该通过 SSH 连接到 Elastic Beanstalk 来安装php-develmongo Those settings will disappear when your EB environment scales in/out or server crash by accident.当您的 EB 环境扩大/缩小或服务器意外崩溃时,这些设置将消失。

Try to use Configuration File to customize your EB Environment.尝试使用配置文件来自定义您的 EB 环境。

Updated: add a configuration file example for PHP 5.4 on 64bit Amazon Linux 2013.09更新:为 64 位 Amazon Linux 2013.09 上的 PHP 5.4 添加配置文件示例

  1. Create an .ebextensions directory in the top-level of your source bundle.在源包的顶层创建一个 .ebextensions 目录。
  2. Create a configuration file, /your_app/.ebextensions/01install_mongo_driver.config .创建配置文件/your_app/.ebextensions/01install_mongo_driver.config

Type the following inside the configuration file 01install_mongo_driver.config to install php mongodb driver.在配置文件01install_mongo_driver.config键入以下01install_mongo_driver.config以安装 php mongodb 驱动程序。

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.因为 64 位 Amazon Linux 2013.09 AMI 上的 PHP 5.4 已经包含php-devel ,所以您不会手动安装它。

Update for MongoDB on PHP 7 on Amazon Linux 2 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

Above adds enables the extension on php.ini and installs mongodb for your PHP.上面添加了在 php.ini 上启用扩展并为您的 PHP 安装 mongodb。 The ignore errors prevents any error if installing a second time.如果第二次安装,则ignore errors可防止出现任何错误。 (eg if your server crashes and has to reboot). (例如,如果您的服务器崩溃并必须重新启动)。 This is to prevent an error that "mongodb is already installed"这是为了防止出现“mongodb 已经安装”的错误

Note: this file is stored in: /your_app_root/.ebextensions/mongo.config注意:此文件存储在:/your_app_root/.ebextensions/mongo.config

As fo today, the correct settings to install mongodb in the latest version of Amazon Linux 2 thru AWS Beanstalk is as follows, everything else fails for me.对于今天,通过 AWS Beanstalk 在最新版本的 Amazon Linux 2 中安装mongodb的正确设置如下,其他一切对我来说都失败了。 If you are unable to solve it, please do as I did and connect to the server a review the logs.如果您无法解决它,请按照我的方法连接到服务器查看日志。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM