Search code examples
phpamazon-elastic-beanstalkphp-mongodb

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?


Solution

  • 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.