从Elastic Beanstalk安装PHP模块

Cha*_*ith 4 php mongodb amazon-elastic-beanstalk

我正在尝试配置AWS Elastic Beanstalk以与mongo一起使用,我所要做的就是为PHP安装mongo驱动程序并更新php.ini文件。

为此,通常我将使用ssh进入EC2并运行:

sudo pecl install mongo
Run Code Online (Sandbox Code Playgroud)

但这将需要使用自定义AMI,这并不是最好的方法。

最好使用配置文件将所需的软件安装到标准AMI上。

为此,我完成了以下操作:创建目录.ebextensions创建文件mongo.config

在其中添加了以下内容:

packages: 
pecl: install mongo
Run Code Online (Sandbox Code Playgroud)

但是,在部署时,出现以下错误:

"option_settings" in one of the configuration files failed validation. More details to follow.
Run Code Online (Sandbox Code Playgroud)

'null' values are not allowed in templates
Run Code Online (Sandbox Code Playgroud)

所以我想知道如何配置此配置文件才能安装mongo扩展?

我在这里阅读了以下信息:http : //docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers-ec2.html

但我不太了解如何执行此特定任务

帮助将不胜感激,谢谢!:)

Phi*_*ber 5

pecl在Amazon Linux上不是有效的软件包管理器,因此不能在配置packages键下使用.ebextensions

要安装PECL软件包,只需在commands密钥下添加一个命令即可。为避免Beanstalk在后续部署中尝试两次安装扩展,请在test密钥中添加一个PHP控制台命令,以检查扩展是否已安装:

commands:
  install_mongo_driver:
    command: pecl install mongo
    test: "php -r \"exit(extension_loaded('mongo') ? 1 : 0);\""
Run Code Online (Sandbox Code Playgroud)

如果test结果是true,即exit(0),那么command被执行的-否则不是。请注意,退出代码0在shell上下文中的意思是“没有错误”。

另请参见http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers-ec2.html#customize-containers-format-commands上的描述。