Lesson 2: Installing the MongoDB PHP Driver / Learn
Code Summary: Installing the MongoDB PHP Driver
The following code demonstrates how to install the MongoDB PHP driver, configure PHP settings, and install the MongoDB PHP library.
Run the following command to install the MongoDB PHP extension by using PECL:
sudo pecl install mongodb
To find your php.ini file path, run the following:
php --ini
Add this line to the bottom of the php.ini file:
extension=mongodb.so
To create a new PHP project, initialize it with Composer, and install the mongodb/mongodb library, run the following commands:
mkdir project && cd project
composer init
composer require mongodb/mongodb:^1.15
composer show mongodb/mongodb
Finally, add this line to the top of your application file so that you can access the Composer libraries:
require_once __DIR__ . '/vendor/autoload.php