W3docs

Installing the PHP 7 MongoDB Client/Driver?

To install the PHP 7 MongoDB driver, you can use the PECL (PHP Extension Community Library) command-line tool.

To install the PHP 7 MongoDB driver, you can use the PECL (PHP Extension Community Library) command-line tool. First, make sure that you have PECL installed on your system. You will also need system-level dependencies like libmongoc and libbson. Then, you can run the following command:

Example of installing the PHP 7 MongoDB driver

pecl install mongodb

This will install the latest version of the MongoDB driver for PHP 7. After the installation is complete, you will need to add the following line to your PHP configuration file (php.ini):

extension=mongodb.so

(Note: Use extension=mongodb.dll on Windows systems.)

Then you will have to restart your web server. You can verify the extension is loaded by running php -m | grep mongodb or checking your phpinfo() output.

Alternatively, you can install the MongoDB userland library via Composer by running the following command:

Example of installing the MongoDB userland library via Composer in PHP

composer require mongodb/mongodb

Make sure your Composer is updated to the latest version. Note that this installs the userland library, not the native driver, so the PECL extension must still be installed for full functionality.