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.

Error From Composer Update
Error From Composer Update

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!

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

Conclusion

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.

Similar Useful Articles


Code, Build, Repeat.
Stay updated with the latest trends and tutorials in Android, iOS, and web development.
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.
canopas-logo
We build products that customers can't help but love!
Get in touch

Whether you need...

  • *
    High-performing mobile apps
  • *
    Bulletproof cloud solutions
  • *
    Custom solutions for your business.
Bring us your toughest challenge and we'll show you the path to a sleek solution.
Talk To Our Experts
footer
Follow us on
2024 Canopas Software LLP. All rights reserved.