无法在Laravel 10中安装jenssegers/mongodb。

huangapple go评论67阅读模式
英文:

Can't install jenssegers/mongodb in Laravel 10

问题

我是新手 Laravel 用户。我想要使用 Laravel 10 连接到 MongoDB,需要安装 jenssegers/mongodb。当我在终端中运行 composer require jenssegers/mongodb 3.8.0 --ignore-platform-reqs 命令时,我收到以下错误信息:

PHP 警告: PHP 启动:无法加载动态库 'php_mongodb.dll'(尝试:D:\ProgramFiles\xampp\php\ext\php_mongodb.dll(找不到指定的模块),D:\ProgramFiles\xampp\php\ext\php_php_mongodb.dll.dll(找不到指定的模块))位于 Unknown on line 0

警告:PHP 启动:无法加载动态库 'php_mongodb.dll'(尝试:D:\ProgramFiles\xampp\php\ext\php_mongodb.dll(找不到指定的模块),D:\ProgramFiles\xampp\php\ext\php_php_mongodb.dll.dll(找不到指定的模块))位于 Unknown on line 0
来自 https://repo.packagist.org 的信息:#StandWithUkraine
./composer.json 已更新
运行 composer update jenssegers/mongodb
加载包信息的 composer 存储库
更新依赖项
无法解决您的要求以安装包的形式。

  问题 1
    - 根 composer.json 需要 jenssegers/mongodb 3.8.0 -> jenssegers/mongodb[v3.8.0] 可满足。
    - jenssegers/mongodb v3.8.0 需要 illuminate/support ^8.0 -> 发现 illuminate/support[v8.0.0,...,v8.83.27],但由于可能与其他要求冲突而未加载。

安装失败,将./composer.json 和./composer.lock还原为其原始内容。

请注意,我使用的是 PHP 8.1.10,并下载了 php_mongodb.dll(从此链接下载,支持 PHP 7.3),将其放入 php\ext 文件夹,并将 extension=php_mongodb.dll 添加到 php.ini 文件,但似乎无法找到此模块,如上面的结果所示。

这是我的 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
}

我尝试了其他命令,如 composer require jenssegers/mongodb:dev-develop --ignore-platform-reqscomposer require jenssegers/mongodb 3.8 --ignore-platform-reqscomposer require jenssegers/mongodb:* --ignore-platform-reqscomposer require jenssegers/mongodb:* 或类似的命令,但没有帮助。

如何解决这个问题?
感谢任何帮助。

英文:

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.

答案1

得分: 11

更新 2023 年 10 月

该包现在有一个新的版本 4,支持 laravel 10。该包本身已更名为 mongodb/laravel-mongodb,因为该包已转移到 MongoDB Inc。仓库链接:https://github.com/mongodb/laravel-mongodb

因此,要在 laravel 10 上安装它,可以运行以下命令,假设您已设置了正确的 PHP MongoDB 扩展版本

composer require mongodb/laravel-mongodb

更新

后来我发现 PHP MongoDB 扩展的 dll 文件可以直接从它们的 github 仓库 下载。所以请访问 此链接 ,您可以获取适用于 Windows 的 MongoDB 扩展 1.15(确保获取与您的 PHP 版本兼容且线程安全的扩展,在文件名中有提到)。因此,下载 MongoDB 扩展 1.15 将允许您解决第 3 和第 4 个问题。

因此,如果您使用 MongoDB 扩展的 1.15 版本,运行以下命令应足以解决 Composer 的问题并使您的应用程序正常运行

composer require jenssegers/mongodb:dev-master

旧回答

目前,以下是存在的问题

  • 您正在使用 laravel 10。jenssegers/mongodb 包目前(在编写此回答时)没有任何支持 laravel 10 的稳定版本(计划很快发布支持 laravel 10 的新版本,但尚未公布发布日期)。因此,您需要使用其 master 分支,该分支已添加对 laravel 10 的支持(请注意,master 分支仍在开发中,可能会出现不兼容更改)。您可以使用以下命令安装 master 分支的代码:
    composer require jenssegers/mongodb:dev-master

  • 您正在使用 PHP 8.1,但您安装了 PHP7.3 的 MongoDB 扩展,它们不兼容。您需要下载兼容的版本,最好是版本 1.13(最新的 Windows 版本)。您可以从此处下载:https://pecl.php.net/package/mongodb/1.13.0/windows(确保下载线程安全版本)

  • jenssegers/mongodb 将尝试安装 mongodb/mongodb 的最新版本,该版本需要 PHP 扩展版本 1.15。不幸的是,版本 1.15 尚未发布适用于 Windows 的版本,因此您将不得不使用该包的版本 1.12,该版本将运行在扩展的版本 1.13 上:
    composer require mongodb/mongodb:^1.12 jenssegers/mongodb:dev-master

  • 现在的最后一个问题是 jenssegers/mongodb 的 master 分支还需要 MongoDB 扩展 1.15。不幸的是,可能没有安全的解决方法。您可以运行:
    composer require mongodb/mongodb:^1.12 jenssegers/mongodb:dev-master --ignore-platform-reqs
    并尝试安装,但在某些情况下可能会工作,也可能不会。

因此,您的选择是

  1. 使用 WSL2 或 Docker 来获取 Linux 环境。然后,您可以安装 PHP 扩展的 1.15 版本,然后只需运行:
    composer require jenssegers/mongodb:dev-master
    即可使其正常工作。
  2. 继续使用 Windows 并降级到 laravel 9。然后,您可以运行:
    composer require mongodb/mongodb:^1.12 jenssegers/mongodb
  3. 忽略平台要求并希望它能正常工作,运行:
    composer require mongodb/mongodb:^1.12 jenssegers/mongodb:dev-master --ignore-platform-reqs

希望这能帮助您。

英文:

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

  • 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 <br> 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 <br> 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 <br> composer require mongodb/mongodb:^1.12 jenssegers/mongodb:dev-master --ignore-platform-reqs <br> and get it to install, but it may or may not work in all cases.

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 <br> composer require jenssegers/mongodb:dev-master <br> and get it to work
  2. Stick to windows and downgrade to laravel 9. Then you may run <br> composer require mongodb/mongodb:^1.12 jenssegers/mongodb
  3. Ignore the platform requirements and hope that it works and run <br> composer require mongodb/mongodb:^1.12 jenssegers/mongodb:dev-master --ignore-platform-reqs

Hope this helps

huangapple
  • 本文由 发表于 2023年2月27日 15:55:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/75577962.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定