Dutch PHP Conference 2025 - Call For Papers

Instalación del Controlador de MongoDB para PHP con PECL

Se puede encontrar información para la instalación de esta extensión PECL en el capítulo del manual titulado Instalación de extensiones PECL. Se puede encontrar información adicional, tal como nuevos lanzamientos, descargas, ficheros fuente, información de mantenimiento, y un CHANGELOG, aquí: » https://pecl.php.net/package/mongodb

Los usuarios de Linux, Unix, y OS X pueden ejecutar el siguiente comando para instalar el controlador:

$ sudo pecl install mongodb

Si su sistema tiene varias versiones de PHP instaladas (p. ej. en macOS, Homebrew, » XAMPP), tenga en cuenta que cada versión de PHP tiene su propio comando pecl y archivophp.ini.

La instalación del controlador a través de PECL utilizará las versiones incluidas de » libbson y » libmongoc e intentará configurarlos automáticamente.

Nota: Si el proceso de compilación no encuentra una biblioteca SSL, compruebe que los paquetes de desarrollo (por ej. libssl-dev) y » pkg-config están instalados. Si eso no resuelve el problema, considere utilizar el proceso de instalación manual.

Añada la siguiente línea al fichero php.ini:

extension=mongodb.so

add a note

User Contributed Notes 7 notes

up
40
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
up
27
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

But:

$ apt-get install pkg-config
...
Setting up pkg-config (0.26-1ubuntu4) ...
$ pecl install mongodb
...
Build process completed successfully
Installing '/usr/lib/php/20151012/mongodb.so'
install ok: channel://pecl.php.net/mongodb-1.1.7
configuration option "php_ini" is not set to php.ini location
You should add "extension=mongodb.so" to php.ini
up
17
asologor at gmail dot com
7 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

or

sudo apt-get install php7.0-mongodb
up
19
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 extension=mongodb.so 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
up
6
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
up
6
Anonymous
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
up
-2
Unmesh
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
To Top