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

avwztpqn  于 2023-02-28  发布在  PHP
关注(0)|答案(1)|浏览(245)

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

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.

请注意,我使用PHP 8.1.10和下载php_mongodb. dll(从this link下载,它支持PHP 7.3)到php\ext文件夹,并添加extension=php_mongodb.dllphp.ini文件,但它看起来像这个模块无法找到,如上面的结果所示。
这是我的 composer

{
    "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:*或类似的,但它没有帮助。
我该怎么解决这个问题呢?任何帮助都将不胜感激。

jmp7cifd

jmp7cifd1#

现在,问题是

  • 您使用的是laravel 10。jenssegers/mongodb软件包当前(在撰写此答案时)没有任何支持laravel 10的稳定版本(有一个新的发布计划很快与支持laravel 10,但没有发布日期宣布)。所以你需要使用他们的主分支,其中增加了对laravel 10的支持(master分支仍在开发中,因此预计会有重大更改)。您可以使用以下命令安装master分支代码

composer require jenssegers/mongodb:dev-master

  • 您使用的是PHP8.1,但是您安装了PHP7.3的MongoDB扩展,它们不兼容。您需要下载一个兼容的版本,最好是1.13版本(最新的windows版本)。您可以从这里下载https://pecl.php.net/package/mongodb/1.13.0/windows(确保下载线程安全版本)
  • jenssegers/mongodb将尝试安装最新版本的mongodb/mongodb,这需要PHP扩展版本1.15。遗憾的是,尚未针对Windows发布版本1.15,因此您必须使用将在版本1.13的扩展上运行的版本1.12的软件包

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环境,然后安装1.15版本的PHP扩展,只需运行
composer require jenssegers/mongodb:dev-master
让它发挥作用
1.坚持windows,降级到laravel 9,然后你可以运行
composer require mongodb/mongodb:^1.12 jenssegers/mongodb
1.忽略平台要求,希望它能正常工作和运行
composer require mongodb/mongodb:^1.12 jenssegers/mongodb:dev-master --ignore-platform-reqs
希望这能帮上忙

相关问题