phplaravelmongodblaravel-8jenssegers-mongodb

Can't install jenssegers/mongodb in Laravel 10


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.


Solution

  • Update October 2023

    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
    

    Update

    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

    Old Answer

    At this moment, here are the issues

    So the options you have are

    1. Use WSL2 or docker to get a linux environment. You can then install the 1.15 version of the PHP extension and you can just run
      composer require jenssegers/mongodb:dev-master
      and get it to work
    2. Stick to windows and downgrade to laravel 9. Then you may run
      composer require mongodb/mongodb:^1.12 jenssegers/mongodb
    3. Ignore the platform requirements and hope that it works and run
      composer require mongodb/mongodb:^1.12 jenssegers/mongodb:dev-master --ignore-platform-reqs

    Hope this helps