Installing Mongodb PHP Drivers on Ubuntu 18.04

10,097

Solution 1

try:

sudo apt-get install php-mongodb

worked for me

Solution 2

I was able to install php-mongodb after adding the ppa repository ondrej/php:

sudo add-apt-repository ppa:ondrej/php
sudo apt update
sudo apt-get install php-mongodb
Share:
10,097
user2165827
Author by

user2165827

Updated on June 15, 2022

Comments

  • user2165827
    user2165827 almost 2 years

    I have installed mongodb on a new Ubuntu 18.04 server. I can access and work with the database through the command line, but cannot access it via PHP, and was wondering how other people have gotten it to work.

    Following a new build of Ubuntu 18.04, and installation of LAMP, I ran:
    sudo apt install mongodb-server php-pear php7.2-dev sudo pecl install mongodb

    I then added the mongodb.so extension to the php.ini file, and a phpinfo(); page shows mongodb as installed. So far so good.

    If I browse to a test php page ($mongo=new Mongo();), the page fails to load though.

    Through web searches, I find the https://github.com/alcaeus/mongo-php-adapter page come up a lot, and I have run the composer installation command there, but to no avail.

    Installed versions are: Ubuntu 18.04.2 LTS; mongoDBv3.6.3; php 7.2.17; Apache 2.4.29

    I was wondering what steps other people who have gotten PHP to work successfully with Mongodb have followed? I plan to scrap this server and start from a fresh VM install again.