由于版本不兼容,无法安装 laravel/sail

Unable to install laravel/sail due to incompatible versions it seems

我正在尝试将 laravel/sail 安装到现有项目中,该项目之前似乎没有安装过。我相信这个项目通常 运行 在 vagrant 上。

我正在尝试 运行ning 在 WSL2 上,使用 Laravel Sail。我也不完全确定这是否是我的最佳方法。

我的理解是,我可以使用 sail 通过 docker 获取项目 运行ning,只需最少的设置和配置。

当我尝试通过 composer 安装 sail 时,我似乎遇到了错误。这些是我遵循的说明:https://laravel.com/docs/9.x/sail#installing-sail-into-existing-applications

这是错误:

$ composer require laravel/sail --dev
PHP Warning:  PHP Startup: Unable to load dynamic library 'pdo_mysql' (tried: /usr/lib/php/20190902/pdo_mysql (/usr/lib/php/20190902/pdo_mysql: cannot open shared object file: No such file or directory), /usr/lib/php/20190902/pdo_mysql.so (/usr/lib/php/20190902/pdo_mysql.so: undefined symbol: mysqlnd_allocator)) in Unknown on line 0
Using version ^1.13 for laravel/sail
./composer.json has been updated
Running composer update laravel/sail
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 laravel/sail ^1.13 -> satisfiable by laravel/sail[v1.13.0, ..., 1.x-dev].
    - laravel/sail[v1.13.0, ..., 1.x-dev] require illuminate/contracts ^8.0|^9.0 -> found illuminate/contracts[v8.0.0, ..., 8.x-dev, v9.0.0-beta.1, ..., 9.x-dev] but these were not loaded, likely because it conflicts with another require.

You can also try re-running composer require with an explicit version constraint, e.g. "composer require laravel/sail:*" to figure out if any version is installable, or "composer require laravel/sail:^2.1" if you know which you need.

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

我不太确定如何解释这一点,但看起来正在尝试安装的版本与另一个必需的包不兼容。

composer.json 文件:

{
        "name": "laravel/laravel",
        "description": "The Laravel Framework.",
        "keywords": [
                "framework",
                "laravel"
        ],
        "license": "MIT",
        "type": "project",
        "require": {
                "php": "^7.4",
                "composer-runtime-api": "^2.0",
                "aws/aws-sdk-php-laravel": "^3.6",
                "doctrine/dbal": "^2.8",
                "fideloper/proxy": "^4.0",
                "guzzlehttp/guzzle": "^7.3",
                "laravel/framework": "6.*",
                "laravel/nexmo-notification-channel": "^2.5",
                "laravel/passport": "9.4.*",
                "laravel/tinker": "^1.0",
                "maatwebsite/excel": "^3.1",
                "nexmo/laravel": "^2.4",
                "rap2hpoutre/laravel-log-viewer": "1.7.*",
                "spatie/laravel-uptime-monitor": "^3.7",
                "vonage/client": "^2.4"
        },
        "require-dev": {
                "barryvdh/laravel-debugbar": "^3.2",
                "barryvdh/laravel-ide-helper": "^2.8",
                "filp/whoops": "^2.0",
                "fzaninotto/faker": "^1.4",
                "mockery/mockery": "^1.0",
                "nunomaduro/collision": "^3.0",
                "phpunit/phpunit": "^7.1"
        },
        "autoload": {
                "classmap": [
                        "database",
                        "app/Http/Controllers",
                        "app/Console/Commands"
                ],
                "psr-4": {
                        "App\": "app/"
                }
        },
        "autoload-dev": {
                "psr-4": {
                        "Tests\": "tests/"
                }
        },
        "extra": {
                "laravel": {
                        "dont-discover": []
                }
        },
        "scripts": {
                "post-root-package-install": [
                        "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
                ],
                "post-create-project-cmd": [
                        "@php artisan key:generate"
                ],
                "post-autoload-dump": [
                        "Illuminate\Foundation\ComposerScripts::postAutoloadDump",
                        "@php artisan package:discover"
                ]
        },
        "config": {
                "platform": {
                        "php": "7.4"
                },
                "preferred-install": "dist",
                "sort-packages": true,
                "optimize-autoloader": true
        },
        "minimum-stability": "dev",
        "prefer-stable": true
}

要解决此问题并避免某些依赖项不兼容,您可以 运行:

composer require laravel/sail --dev --ignore-platform-reqs

但这不是一个很好的做法。

不幸的是,根据您当前的 Laravel 框架版本,您 无法使用 laravel/sail

解释:

laravel/sail="1.13" requires illuminate/contracts: ^8.0|^9.0`

现在,问自己一个问题,在Laravel v6中哪些包依赖于illuminate/contracts?

命令:composer depends illuminate/contracts

输出:

Info from https://repo.packagist.org: #StandWithUkraine
fideloper/proxy    4.4.1     requires  illuminate/contracts (^5.0|^6.0|^7.0|^8.0|^9.0)
laravel/framework  v6.18.43  replaces  illuminate/contracts (self.version)
laravel/tinker     v1.0.10   requires  illuminate/contracts (~5.1|^6.0)

基于上面的输出,你有点意识到common illuminate/contracts 所有依赖之间的版本是 ^6.0.

考虑到这一点,您通常需要安装需要 illuminate/contractslaravel/sail 版本:^6.0`

不幸的是,不可能。之所以如此,是因为即使是第一个 laravel/sail 版本 (dev-develop) 也需要 illuminate/contracts: ^8.0|^9.0|^10.0.

现在,最合理的选择是先升级依赖illuminate/contracts的包你的项目。在上面 output 的所有 3 个包中,是 Laravel 框架。可悲的是,第一个满足 illuminate/contracts: ^8.0|^9.0 要求的框架版本是 laravel/framework v8.0.0. If that is something you would consider, then you may want to look at the Laravel 8 upgrade guide.

可能的解决方案:

考虑到 Laravel Sail 只是一个工具,可以为您提供使用 PHP、MySQL 和 Redis 构建 Laravel 应用程序的起点,而无需事先Docker 经验,还有其他工具可以以类似的方式完成工作。

我可能建议的一个工具是 Laradock


如果您有足够的 docker 经验,您甚至可以借助现成的 public 官方 [=86] 从头开始​​ docker set-up =] 图片来自 Docker Hub.