[英]installing PHP module from Elastic Beanstalk
I am trying to configure my AWS Elastic Beanstalk to work with mongo, all I need to do is install the mongo driver for PHP and update the php.ini file 我正在尝试配置我的AWS Elastic Beanstalk以使用mongo,我需要做的就是为PHP安装mongo驱动程序并更新php.ini文件
To do this, usually I would ssh into the EC2 and run: 要做到这一点,通常我会进入EC2并运行:
sudo pecl install mongo
But this would require using a custom AMI which isnt the best way to go. 但这需要使用自定义AMI,这不是最好的方法。
It is better to use config files to install the software required onto the standard AMI. 最好使用配置文件来安装标准AMI所需的软件。
So to do this, I have done the following: created directory .ebextensions created file mongo.config 所以要做到这一点,我已经完成了以下工作:创建目录.ebextensions创建文件mongo.config
in it I have put the following: 在其中我提出以下内容:
packages:
pecl: install mongo
However upon deployment, I get the following error: 但是在部署时,我收到以下错误:
"option_settings" in one of the configuration files failed validation. More details to follow.
and 和
'null' values are not allowed in templates
So I am wondering how this config file needs to be laid out in order to install the mongo extension? 所以我想知道如何配置这个配置文件以安装mongo扩展?
I have read the info here: http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers-ec2.html 我在这里阅读了这些信息: http : //docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers-ec2.html
but I am not quite understanding how to do this specific task 但我不太了解如何完成这项具体任务
Help would be appreciated , thanks! 感谢帮助,谢谢! :)
:)
pecl
is not a valid package manager on Amazon Linux and therefore cannot be used under the packages
key of an .ebextensions
config. pecl
不是Amazon Linux上的有效包管理器,因此不能在.ebextensions
配置的packages
键下使用。
To install a PECL package it is enough to add a single command under the commands
key. 要安装PECL包,只需在
commands
键下添加一个commands
。 To avoid that Beanstalk tries to install the extension twice on follow-up deployments add a PHP console command to the test
key that checks if the extension is already installed: 为避免Beanstalk尝试在后续部署中安装两次扩展,请在
test
密钥中添加一个PHP控制台命令,以检查是否已安装扩展:
commands:
install_mongo_driver:
command: pecl install mongo
test: "php -r \"exit(extension_loaded('mongo') ? 1 : 0);\""
If the test
result is true
, ie exit(0)
, then the command
gets executed - otherwise not. 如果
test
结果为true
,即exit(0)
,则执行command
- 否则不执行。 Please note that a exit code of 0
means "No errors" in a shell context. 请注意,退出代码
0
表示shell上下文中的“无错误”。
See also the description at http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers-ec2.html#customize-containers-format-commands . 另请参阅http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers-ec2.html#customize-containers-format-commands中的说明。
I have figured it out and thought I would share what I found. 我已经弄清楚了,并认为我会分享我发现的东西。 Thanks to Hudku ( http://blog.hudku.com/2013/02/innocuous-looking-evil-devil.html#elastic-beanstalk.config ) for the excellent article:
感谢Hudku( http://blog.hudku.com/2013/02/innocuous-looking-evil-devil.html#elastic-beanstalk.config )的优秀文章:
1) Create myapp.config 2) enter the following into it 1)创建myapp.config 2)在其中输入以下内容
packages:
yum:
dos2unix: []
container_commands:
01-command:
command: rm -rf /myapp/ebextensions
02-command:
command: mkdir -p /myapp/ebextensions
03-command:
command: cp -R .ebextensions/* /myapp/ebextensions/
04-command:
command: dos2unix -k /myapp/ebextensions/mongo.sh
05-command:
command: chmod 700 /myapp/ebextensions/mongo.sh
06-command:
command: bash /myapp/ebextensions/mongo.sh
Then create mongo.sh file and put in it something like: 然后创建mongo.sh文件并输入如下内容:
#!/bin/bash
if [ ! -f /mongostatus.txt ];
then
pecl install mongo
echo "mongo extension installed" > /mongostatus.txt
apachectl restart
fi
This will install mongo php extension and restart apache so the install takes affect. 这将安装mongo php扩展并重启apache,以便安装生效。
I just accomplished the same thing thanks to the answer above, and figured out it can be done with less lines and less files for those interested... 由于上面的答案,我刚刚完成了同样的事情,并且发现它可以用更少的行和更少的文件为感兴趣的人完成...
# ~/project/.ebextensions/project.config
# Logger messages can be viewed in /var/log/messages
files:
"/tmp/test.sh":
content: |
# This file will be created and can then
# be executed by a command call below.
logger TEST FILE CALLED
commands:
01-command:
command: logger CALLING TEST FILE; sh /tmp/test.sh;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.