Setup PHP MongoDB Extension On MAC And Windows

Resolve missing MongoDB extension error
Jan 11 2021 · 2 min read

Introduction

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.

1_PKmrzJSKcV9iwarQC6lhAQ.webp

The above error shows that MongoDB is not installed and if installed then the extension is not added to the php.ini file.


Investigation

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.


Solution

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


Similar articles


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.


sumita-k image
Sumita Kevat
Sumita is an experienced software developer with 5+ years in web development. Proficient in front-end and back-end technologies for creating scalable and efficient web applications. Passionate about staying current with emerging technologies to deliver.


sumita-k image
Sumita Kevat
Sumita is an experienced software developer with 5+ years in web development. Proficient in front-end and back-end technologies for creating scalable and efficient web applications. Passionate about staying current with emerging technologies to deliver.

background-image

Get started today

Let's build the next
big thing!

Let's improve your business's digital strategy and implement robust mobile apps to achieve your business objectives. Schedule Your Free Consultation Now.

Get Free Consultation
footer
Subscribe Here!
Follow us on
2024 Canopas Software LLP. All rights reserved.