PHP 8.4.0 Alpha 2 available for testing

Installing the MongoDB PHP Extension with PECL

安装此 PECL 扩展相关的信息可在手册中标题为 PECL 扩展的安装章节中找到。更多信息如新的发行版本、下载、源文件、 维护人员信息及变更日志等,都在此处: »

Linux, Unix, and macOS users may run the following command to install the extension:

$ sudo pecl install mongodb

On systems with multiple version of PHP installed (e.g. macOS default, Homebrew, » XAMPP), each version of PHP will have its own pecl command and php.ini file(s). Additionally, each PHP environments (e.g. CLI, web) may use separate php.ini files.

As of extension version 1.17.0, PECL will prompt for various configure options. To install the extension with default options in a non-interactive script, empty string input may be piped to pecl install using the yes command:

$ yes '' | sudo pecl install mongodb

A complete list of supported configure options can be found in the package.xml file included in the PECL package. To install the extension with specific configure options in a non-interactive script, the --configureoptions option for pecl install may be used:

$ sudo pecl install --configureoptions='with-mongodb-system-libs="yes" enable-mongodb-developer-flags="no"' mongodb

By default, installing the extension via PECL will use bundled versions of » libbson, » libmongoc, and » libmongocrypt and attempt to automatically configure them.

注意: If the build process fails to find an SSL library, check that the development packages (e.g. libssl-dev) and » pkg-config are both installed. If that does not resolve the problem, consider using the manual installation process.

Finally, add the following line to the php.ini file for each environment that will need to use the extension:

add a note

User Contributed Notes 9 notes

mohammadhoseinmazalahi at gmail dot com
4 years ago
As of Ubuntu 20.04, php-mongodb in the database is outdated and you'll need the PECL method to install latest version of MongoDB.

To do this in Ubuntu, you'll need the php-pear plugin and php-dev:
sudo apt install php-dev php-pear

then you can run:
sudo pecl install mongodb
contact ? automatix : info
8 years 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
asologor at gmail dot com
6 years ago
On Ubuntu you can just do:

sudo apt-get install php-mongodb

or the same for specific PHP version:

sudo apt-get install php5.6-mongo


sudo apt-get install php7.0-mongodb
rafael_xuvisco at yahoo dot com dot br
7 years 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
Tim Greiser
8 years 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
7 years 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
7 years ago
The following steps worked for me on Centos7

sudo yum install -y openssl-devel
sudo yum install pecl
sudo yum install gcc
sudo pecl install mongodb
maneesh dot singh at hof-university dot com
7 years 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
7 years 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