Laravel MongoDB fails installing jenssegers/mongodb

By bhagwatchouhan
Laravel MongoDB fails installing jenssegers/mongodb

We might face an error while working with Laravel and MongoDB. When we try to install the composer dependency jenssegers/mongodb, it might throw an error having the description - Your requirements could not be resolved to an installable set of packages.

 

Steps to produce the error

 

PHP is already installed on the system. You can follow How To Install PHP On Windows, How To Install PHP 7 On Windows, How To Install XAMPP On Windows 10, How To Install WampServer on Windows, and  How To Install PHP 8 On Ubuntu 20.04 LTS. Also, the PHP path is set on the Windows system as mentioned in the PHP installation tutorials How To Install PHP On Windows and How To Install PHP 7 On Windows.

 

MongoDB is already installed on the system. You can follow How To Install MongoDB on Windows, How To Install MongoDB on Ubuntu Desktop, and How To Install MongoDB on Ubuntu.

 

Now try to install the composer dependency jenssegers/mongodb as shown below.
 

 

# Install
composer require jenssegers/mongodb

# Output
Using version ^3.8 for jenssegers/mongodb
./composer.json has been updated
Running composer update jenssegers/mongodb
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.

Problem 1
- jenssegers/mongodb[v3.8.0, ..., 3.8.4] require mongodb/mongodb ^1.6 -> satisfiable by mongodb/mongodb[1.6.0, ..., 1.10.x-dev (alias of dev-master)].
- mongodb/mongodb 1.10.x-dev is an alias of mongodb/mongodb dev-master and thus requires it to be installed too.
- mongodb/mongodb dev-master requires ext-mongodb ^1.11.0 -> it is missing from your system. Install or enable PHP's mongodb extension.
- mongodb/mongodb[1.6.0, ..., v1.6.x-dev] require ext-mongodb ^1.7 -> it is missing from your system. Install or enable PHP's mongodb extension.
- mongodb/mongodb[1.7.0-beta1, ..., v1.7.x-dev] require ext-mongodb ^1.8 -> it is missing from your system. Install or enable PHP's mongodb extension.
- mongodb/mongodb[1.8.0-RC1, ..., v1.8.x-dev] require ext-mongodb ^1.8.1 -> it is missing from your system. Install or enable PHP's mongodb extension.
- mongodb/mongodb[1.9.0-alpha1, ..., v1.9.x-dev] require ext-mongodb ^1.10.0 -> it is missing from your system. Install or enable PHP's mongodb extension.
- Root composer.json requires jenssegers/mongodb ^3.8 -> satisfiable by jenssegers/mongodb[v3.8.0, ..., 3.8.4].

To enable extensions, verify that they are enabled in your .ini files:
- E:\tools\php\wamp64\bin\php\php7.4.9\php.ini
You can also run `php --ini` inside terminal to see which files are used by PHP in CLI mode.

Installation failed, reverting ./composer.json and ./composer.lock to their original content.

 

We can see that the installation of jenssegers/mongodb for the Laravel application failed with the error message - Your requirements could not be resolved to an installable set of packages.

 

Error Resolution

 

Download the compatible .DLL or .SO file for MongoDB based on your current PHP version and update the PHP .ini file configured on the system path.

 

In my case, it was PHP 7.4 installed on Windows 10 using WampServer, hence I have downloaded the thread-safe version of php_mongodb.dll from the official website and copied it to the PHP extension directory wamp64\bin\php\php7.4.9\ext. Also, I have configured the .ini file by appending the below-mentioned line at last.

 

# MongoDB Extension
extension=php_mongodb.dll

 

Now restart your Web Server and confirm whether the extension is enabled as shown in Fig and also check the output of phpinfo function. It should show MongoDB as shown in Fig 2.

 

jenssegers/mongodb installation failed for laravel - PHP MongoDB Extension Enabled

Fig 1

 

jenssegers/mongodb installation failed for laravel - PHP MongoDB Extension phpinfo

Fig 2

 

Now try to install the composer dependency jenssegers/mongodb. It should succeed as shown below.

 

# Install 
composer require jenssegers/mongodb

# Output
Using version ^3.8 for jenssegers/mongodb
./composer.json has been updated
Running composer update jenssegers/mongodb
Loading composer repositories with package information
Updating dependencies
Lock file operations: 3 installs, 0 updates, 0 removals
- Locking jean85/pretty-package-versions (2.0.4)
- Locking jenssegers/mongodb (3.8.4)
- Locking mongodb/mongodb (1.9.0)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 3 installs, 0 updates, 0 removals
- Downloading jean85/pretty-package-versions (2.0.4)
- Downloading mongodb/mongodb (1.9.0)
- Downloading jenssegers/mongodb (3.8.4)
- Installing jean85/pretty-package-versions (2.0.4): Extracting archive
- Installing mongodb/mongodb (1.9.0): Extracting archive
- Installing jenssegers/mongodb (3.8.4): Extracting archive
2 package suggestions were added by new dependencies, use `composer suggest` to see details.
Package sebastian/resource-operations is abandoned, you should avoid using it. No replacement was suggested.
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi
Discovered Package: facade/ignition
Discovered Package: fruitcake/laravel-cors
Discovered Package: jenssegers/mongodb
Discovered Package: laravel/sail
Discovered Package: laravel/sanctum
Discovered Package: laravel/tinker
Discovered Package: nesbot/carbon
Discovered Package: nunomaduro/collision
Package manifest generated successfully.
77 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
> @php artisan vendor:publish --tag=laravel-assets --ansi
No publishable resources for tag [laravel-assets].
Publishing complete.

 

Summary

 

This tutorial provided the steps to configure the MongoDB extension for PHP and provided the resolution to the error encountered while installing the composer dependency jenssegers/mongodb for the Laravel project.

Share this blog:

Profile picture for user bhagwatchouhan
bhagwatchouhan