I am new to Laravel. I want to connect to MongoDB using Laravel 10 which require jenssegers/mongodb to be installed. When I run command composer require jenssegers/mongodb 3.8.0 --ignore-platform-reqs
in the terminal, I got error like this:
PHP Warning: PHP Startup: Unable to load dynamic library 'php_mongodb.dll' (tried: D:\ProgramFiles\xampp\php\ext\php_mongodb.dll (The specified module could not be found), D:\ProgramFiles\xampp\php\ext\php_php_mongodb.dll.dll (The specified module could not be found)) in Unknown on line 0
Warning: PHP Startup: Unable to load dynamic library 'php_mongodb.dll' (tried: D:\ProgramFiles\xampp\php\ext\php_mongodb.dll (The specified module could not be found), D:\ProgramFiles\xampp\php\ext\php_php_mongodb.dll.dll (The specified module could not be found)) in Unknown on line 0
Info from https://repo.packagist.org: #StandWithUkraine
./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
- Root composer.json requires jenssegers/mongodb 3.8.0 -> satisfiable by jenssegers/mongodb[v3.8.0].
- jenssegers/mongodb v3.8.0 requires illuminate/support ^8.0 -> found illuminate/support[v8.0.0, ..., v8.83.27] but these were not loaded, likely because it conflicts with another require.
Installation failed, reverting ./composer.json and ./composer.lock to their original content.
Note that I use PHP 8.1.10 and download php_mongodb.dll (download from this link and it support PHP 7.3) to php\ext
folder and add extension=php_mongodb.dll
to php.ini
file but it look like this module could not be found as show in the result above.
This is my composer.json:
{
"name": "laravel/laravel",
"type": "project",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"require": {
"php": "^8.1",
"guzzlehttp/guzzle": "^7.2",
"laravel/framework": "^10.0",
"laravel/sanctum": "^3.2",
"laravel/tinker": "^2.8",
"laravel/ui": "^4.2"
},
"require-dev": {
"fakerphp/faker": "^1.9.1",
"laravel/pint": "^1.0",
"laravel/sail": "^1.18",
"mockery/mockery": "^1.4.4",
"nunomaduro/collision": "^7.0",
"phpunit/phpunit": "^10.0",
"spatie/laravel-ignition": "^2.0"
},
"autoload": {
"psr-4": {
"App\\": "app/",
"Database\\Factories\\": "database/factories/",
"Database\\Seeders\\": "database/seeders/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"scripts": {
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"@php artisan package:discover --ansi"
],
"post-update-cmd": [
"@php artisan vendor:publish --tag=laravel-assets --ansi --force"
],
"post-root-package-install": [
"@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"@php artisan key:generate --ansi"
]
},
"extra": {
"laravel": {
"dont-discover": []
}
},
"config": {
"optimize-autoloader": true,
"preferred-install": "dist",
"sort-packages": true,
"allow-plugins": {
"pestphp/pest-plugin": true,
"php-http/discovery": true
}
},
"minimum-stability": "stable",
"prefer-stable": true
}
I had tried another command like composer require jenssegers/mongodb:dev-develop --ignore-platform-reqs
, composer require jenssegers/mongodb 3.8 --ignore-platform-reqs
, composer require jenssegers/mongodb:* --ignore-platform-reqs
, composer require jenssegers/mongodb:*
or similar but it didn't help.
How do I solve this problem? Any help would be appreciated.
The package now has a new version 4 that supports laravel 10. The package itself got renamed to mongodb/laravel-mongodb
as the package was transferred over to MongoDB Inc. Link to repo: https://github.com/mongodb/laravel-mongodb
So to install it on laravel 10, you can run the following command assuming you have setup the correct PHP MongoDB extension version
composer require mongodb/laravel-mongodb
So I later found out that the PHP MongoDB extension dll files can be downloaded directly from their github repo. So visit this link and you can get the MongoDB extension 1.15 for Windows ( Make sure to get the correct extension for your PHP version and that its thread safe. It's mentioned in the file name ). So downloading the MongoDB extension 1.15 will allow to overcome the 3rd and 4th issues.
So if you use the 1.15 version of the mongodb extension, running
composer require jenssegers/mongodb:dev-master
should be enough to fix composer issues and get your application running
At this moment, here are the issues
You are using laravel 10. The jenssegers/mongodb
package currently (at the time of writing this answer ) does not have any stable versions that support laravel 10 ( There is a new released planned soon with support for laravel 10, but no release date announced ). So you would need to use their master branch which has added support for laravel 10 ( master branch is still undergoing development, so expect breaking changes ). You can install the master branch code using
composer require jenssegers/mongodb:dev-master
You are using PHP 8.1, but you installed the MongoDB extension for PHP7.3, and they are not compatible. You need to download a compatible version, preferable version 1.13 ( the latest windows version ). You can download it from here https://pecl.php.net/package/mongodb/1.13.0/windows ( Be sure to download the thread safe version )
jenssegers/mongodb
will try to install the latest version of mongodb/mongodb
, which requires the PHP extension version 1.15. Unfortunately, version 1.15 is not yet released for windows, so you will have to use version 1.12 of the package which will run on version 1.13 of the extension
composer require mongodb/mongodb:^1.12 jenssegers/mongodb:dev-master
Now the last issue is that the master branch of jenssegers/mongodb
also requires MongoDB extension 1.15. Unfortunately, there's probably no safe way around this. You could run
composer require mongodb/mongodb:^1.12 jenssegers/mongodb:dev-master --ignore-platform-reqs
and get it to install, but it may or may not work in all cases.
So the options you have are
composer require jenssegers/mongodb:dev-master
composer require mongodb/mongodb:^1.12 jenssegers/mongodb
composer require mongodb/mongodb:^1.12 jenssegers/mongodb:dev-master --ignore-platform-reqs
Hope this helps