With Laravel, there is a case when you will encounter the requested PHP extension MongoDB is missing from your system error when running composer commands.
The above error shows that MongoDB is not installed and if installed then the extension is not added to the php.ini file.
We are what we repeatedly do. Excellence, then, is not an act, but a habit. Try out Justly and start building your habits today!
To check it, run the command
php -m
It will display all installed extensions for PHP. You will notice that there is no MongoDB extension present in the result.
MongoDB extension should be referenced in the php.ini file when we want to add it in PHP.
Here are defined extension files that are supported on different platforms
mongodb.so for MacOS
php_mongodb.dll for windows
You can get the php.ini file path by running the below command,
php --ini
Let's add it.
After spending too much time finding a solution to handle this error, I found a quite easy solution for this with the PECL command, which I will share with you.
Assuming that you have installed PHP on your machine.
If you are running with xampp, then pecl is already installed with PHP, So skip the below step.
Install PECL as following steps.
curl -s -O https://pear.php.net/install-pear-nozlib.phar
php install-pear-nozlib.phar
Now Run,
pecl install mongodb
This will download MongoDB.
Add an extension in the php.ini file as
extension=mongodb.so on MacOS
extension=mongodb on Windows
Restart the command prompt and if you run
php -m
The result will show the MongoDB extension.
Cheers…… 😎
Now You can successfully install or update the composer without an error.
composer install or composer update
We’re Grateful to have you with us on this journey!
Suggestions and feedback are more than welcome!
Please reach us at Canopas Twitter handle @canopas_eng with your content or feedback. Your input enriches our content and fuels our motivation to create more valuable and informative articles for you.
Whether you need...