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

Viewed 1365

I'm trying to install laravel/sail into an existing project, which doesn't appear to have had it installed before. This project is normally run on vagrant I believe.

I'm trying to get it running on WSL2, using Laravel Sail. I'm also not entirely sure if that's the best approach in my case.

My understanding is that I can use sail to get the project running via docker, with minimal setup and configuration.

I seem to be getting an error when I try to install sail via composer. These are the instructions I'm following: https://laravel.com/docs/9.x/sail#installing-sail-into-existing-applications

Here's the error:

$ 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.

I'm not entirely sure how to interpret this, but it looks like the version that is attempting to be installed is not compatible with another required package.

composer.json file:

{
        "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
}
2 Answers

Unfortunately, you won't be able to work with laravel/sail based on your current Laravel framework version.

Explanation:

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

Now, ask yourself a question, what packages depend on illuminate/contracts in Laravel v6?

Command: composer depends illuminate/contracts

Output:

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)

Based on the output above, you kind of realize that the common illuminate/contracts version between all dependents is ^6.0.

With that in mind, you would normally need to install a laravel/sail version that requires illuminate/contracts: ^6.0`

Unfortunately, that isn't possible. This is so because even the first laravel/sail version (dev-develop) requires illuminate/contracts: ^8.0|^9.0|^10.0.

Now, the most reasonable option would be to first upgrade the package(s) that depend on illuminate/contracts in your project. Among all 3 packages in the output above, is the Laravel framework. Sadly enough, the first framework version that meets the illuminate/contracts: ^8.0|^9.0 requirement is laravel/framework v8.0.0. If that is something you would consider, then you may want to look at the Laravel 8 upgrade guide.

Possible solution:

Considering that Laravel Sail is simply a tool to provide you with a starting point for building a Laravel application using PHP, MySQL, and Redis without requiring prior Docker experience, there are other tools that can get the job done in a similar fashion.

One tool I may suggest is Laradock.


If you have enough docker experience, you could even roll out your own docker set-up from scratch with the help of readily available public official docker images from Docker Hub.

To fix this and avoid the incompatibility of certain dependencies, you can run:

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

But it's not a very good practice.

Related