The MongoDB PHP extension supports PHP 5.4, 5.5, 5.6, 7.0, 7.1, 7.2, and 7.3.
To install this extension, run the following commands as your server's root user:
sudo apt-get -y install gcc make autoconf libc-dev pkg-config sudo apt-get -y install libssl-dev sudo peclX.Y-sp install mongodb
Once installed, create a configuration file for the extension and restart PHP by running the following commands as root:
sudo bash -c "echo extension=mongodb.so > /etc/phpX.Y-sp/conf.d/mongodb.ini" sudo service phpX.Y-fpm-sp restart
You can verify the MongoDB extension is installed by running this command:
phpX.Y-sp -i | grep -i mongodb
You should see output such as the following:
/etc/phpX.Y-sp/conf.d/mongodb.ini, mongodb mongodb support => enabled mongodb version => 1.1.8 mongodb stability => stable mongodb.debug => no value => no value
To uninstall this extension, as root run the commands:
sudo rm /etc/phpX.Y-sp/conf.d/mongodb.ini sudo peclX.Y-sp uninstall mongodb
Next, restart PHP-FPM with the command:
sudo service phpX.Y-fpm-sp restart
Once you've installed the mongodb PHP extension, the easiest way to use the extension is through the MongoDB PHP library.
See the PHP documentation for a tutorial on using the MongoDB PHP library.
If you previously installed the older mongo extension (the mongo extension is different than the mongodb extension), you can remove it with the following commands run as root:
sudo rm /etc/phpX.Y-sp/conf.d/mongo.ini sudo service phpX.Y-fpm-sp restart