Installing the MongoDB PHP Driver with PECL

Information for installing this PECL extension may be found in the manual chapter titled Installation of PECL extensions. Additional information such as new releases, downloads, source files, maintainer information, and a CHANGELOG, can be located here: »

Linux, Unix, and OS X users may run the following command to install the driver:

$ sudo pecl install mongodb

Note: Installing the driver via PECL will use bundled versions of » libbson and » libmongoc and rely on PHP to find OpenSSL (i.e. PHP_SETUP_OPENSSL). If the build process fails to find OpenSSL, check that the OpenSSL development package (e.g. libssl-dev) and » pkg-config are both installed.

Add the following line to your php.ini file:

add a note add a note

User Contributed Notes 6 notes

contact ? automatix : info
8 months ago
An additional requirement might be pkg-config (on Ubuntu 14.04).

$ pecl install mongodb
configure: error: Cannot find OpenSSL's libraries
ERROR: `/tmp/pear/temp/mongodb/configure --with-php-config=/usr/bin/php-config' failed


$ apt-get install pkg-config
Setting up pkg-config (0.26-1ubuntu4) ...
$ pecl install mongodb
Build process completed successfully
Installing '/usr/lib/php/20151012/'
install ok: channel://
configuration option "php_ini" is not set to php.ini location
You should add "" to php.ini
Tim Greiser
9 months ago
[Editor's note: fixed typo]

There are some additional requirements you need to build the pecl package.

sudo apt-get install libcurl4-openssl-dev pkg-config libssl-dev libsslcommon2-dev
rafael_xuvisco at yahoo dot com dot br
4 months ago
Ubuntu 16.04

sudo apt-get install libcurl4-openssl-dev pkg-config libssl-dev libsslcommon2-dev

sudo pecl install mongodb

add in fpm and cli:

sudo vim /etc/php/7.0/fpm/conf.d/30-mongodb.ini

sudo vim /etc/php/7.0/cli/conf.d/30-mongodb.ini

Restart service:

sudo systemctl restart php7.0-fpm

sudo systemctl reload nginx
6 months ago
I got an error "fatal error: pcre.h: No such file or directory" and had to also had to install another dependency

sudo apt-get install libpcre3-dev
maneesh dot singh at hof-university dot com
1 month ago
I am looking into installation of php mongo db driver.
I have checked with phpinfo it shows mongodb module have been loaded but when I use in my code it give error "Fatal error: Uncaught Error: Class 'MongoDB' not found "

i have another module for redis and it works perfectly . Initially I was getting same error but phpinfo was showing module is not loaded .

I guess there is some problem with driver. I have tried all the documents and website links which mention to include which i have already done.

I am using open suse 42.2 leap with apache server.

Could you please investigate this issue.
If you need more info please let me know.

ovidius at email dot it
1 month ago
after installed and added extension=mongodb to php.ini, when i run php -v i get this error:

bus error php -v

what could it be? the build process completed successfully.
To Top