Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

To do this, usually I would ssh into the EC2 and run:

sudo pecl install mongo

But this would require using a custom AMI which isnt the best way to go.

It is better to use config files to install the software required onto the standard AMI.

So to do this, I have done the following: created directory .ebextensions created file 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?

I have read the info here: 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! :)

like image 718
Lawrence Cooke Avatar asked Feb 18 '23 03:02

Lawrence Cooke


1 Answers

pecl is not a valid package manager on Amazon Linux and therefore cannot be used under the packages key of an .ebextensions config.

To install a PECL package it is enough to add a single command under the commands key. 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:

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

If the test result is true, i.e. exit(0), then the command gets executed - otherwise not. Please note that a exit code of 0 means "No errors" in a shell context.

See also the description at http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers-ec2.html#customize-containers-format-commands.

like image 162
Philipp Rieber Avatar answered Feb 27 '23 10:02

Philipp Rieber