Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installing php mongo driver on AWS Elastic Beanstalk

I am trying to deploy a php application on Elastic Beanstalk. Everything is working fine except from my calls to the mongo driver.

My attempt to install it followed these steps (unsuccessfully):

  1. SSH to Elastic Beanstalk instance.
  2. sudo yum install php-devel (for phpize)
  3. sudo pecl install mongo
  4. follow instructions to try command: sudo echo "extension=mongo.so" >> /etc/php.ini with failure. error message is:

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

Am I going about this the right way?

like image 421
Lehel Avatar asked Jan 28 '26 02:01

Lehel


2 Answers

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.

like image 103
study Avatar answered Jan 29 '26 14:01

study


Update for MongoDB on PHP 7 on Amazon Linux 2

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. The ignore errors prevents any error if installing a second time. (e.g. if your server crashes and has to reboot). This is to prevent an error that "mongodb is already installed"

Note: this file is stored in: /your_app_root/.ebextensions/mongo.config

like image 31
hitwill Avatar answered Jan 29 '26 14:01

hitwill