Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

stratboy's avatar

Can't run migrations with Docker: php version mismatch

Hi, running on Docker here. The app us running well (default installation demo) but my first attempt to run

php artisan migrate

ended in the following error message:

Fatal error: Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 8.0.2". You are running 7.3.27. in [...]/vendor/composer/platform_check.php on line 24

Why? I believed the reason for using Docker + Sail was having a self contained environment... So no problems with php versions and the like... What am I doing wrong?

0 likes
24 replies
jlrdw's avatar

See if you installed a version with 7.3.27. Which laravel needs >= 8.0.2, as 9.0 isn't out yet.

edit

I don't use a container, I use the zip archives and extract them, much easier. See reply in your other question, https://laracasts.com/discuss/channels/laravel/what-environment-for-development but just fyi.

Also laravel 8.* needs:

"require": {
        "php": "^7.3|^8.0",
         ......

So 7.3.27 will work, but I don't know your other dependencies.

stratboy's avatar

I already have it configured like you said:

    "require": {
        "php": "^7.3|^8.0",
        "fruitcake/laravel-cors": "^2.0",
        "guzzlehttp/guzzle": "^7.0.1",
        "laravel/framework": "^8.75",
        "laravel/sanctum": "^2.11",
        "laravel/tinker": "^2.5"
    },

I'm currently using Docker since recommended by official docs, as an easy way...

Sinnbeck's avatar

Show your docker-compose.yml file

And are you sure that you are inside the docker container when you migrate?

Try this instead

sail artisan migrate
stratboy's avatar

@Sinnbeck That didn't work. Or, the command was executed, but an error was thrown. Instead of keep trying to make sail work, at the moment I prefer trying another way, like valet, or even maybe just mamp pro..

Sinnbeck's avatar

@stratboy Thats. Fair. Let me know if you pick up docker later. I use it daily and its cool :)

Sinnbeck's avatar

@stratboy I can see you still want to get this working. If you share the error, it will be easier to help

stratboy's avatar

@jlrdw No, I didn't see there were docker videos. I'll watch them for sure thank you

stratboy's avatar

@Sinnbeck Hi, yes, I was able to solve at least the php problem. Now when I run sail artisan migrate, I get:

   Illuminate\Database\QueryException 

  SQLSTATE[HY000] [1045] Access denied for user 'sail'@'172.23.0.7' (using password: YES) (SQL: select * from information_schema.tables where table_schema = testsite4 and table_name = migrations and table_type = 'BASE TABLE')
Sinnbeck's avatar

@stratboy Great. Have you changed the data at any point since your installed sail? If so, then the credentials are wrong.

Try this

sail down -v
sail build --no-cache
sail up -d
stratboy's avatar

@Sinnbeck doesn't work. So I checked the db:

docker-compose exec mysql bash
mysql -u sail -p # doesn't work
mysql -u root -p # it works, without password
show databases; # it properly shows testsite4
use mysql;
select user, host from user;

+------------------+-----------+
| user             | host      |
+------------------+-----------+
| root             | %         |
| healthchecker    | localhost |
| mysql.infoschema | localhost |
| mysql.session    | localhost |
| mysql.sys        | localhost |
| root             | localhost |
+------------------+-----------+

No sail user here.

stratboy's avatar

@Sinnbeck

# For more information: https://laravel.com/docs/sail
version: '3'
services:
    laravel.test:
        build:
            context: ./vendor/laravel/sail/runtimes/8.1
            dockerfile: Dockerfile
            args:
                WWWGROUP: '${WWWGROUP}'
        image: sail-8.1/app
        extra_hosts:
            - 'host.docker.internal:host-gateway'
        ports:
            - '${APP_PORT:-80}:80'
        environment:
            WWWUSER: '${WWWUSER}'
            LARAVEL_SAIL: 1
            XDEBUG_MODE: '${SAIL_XDEBUG_MODE:-off}'
            XDEBUG_CONFIG: '${SAIL_XDEBUG_CONFIG:-client_host=host.docker.internal}'
        volumes:
            - '.:/var/www/html'
        networks:
            - sail
        depends_on:
            - mysql
            - redis
            - meilisearch
            - selenium
    mysql:
        image: 'mysql/mysql-server:8.0'
        ports:
            - '${FORWARD_DB_PORT:-3306}:3306'
        environment:
            MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}'
            MYSQL_ROOT_HOST: "%"
            MYSQL_DATABASE: '${DB_DATABASE}'
            MYSQL_USER: '${DB_USERNAME}'
            MYSQL_PASSWORD: '${DB_PASSWORD}'
            MYSQL_ALLOW_EMPTY_PASSWORD: 1
        volumes:
            - 'sailmysql:/var/lib/mysql'
        networks:
            - sail
        healthcheck:
            test: ["CMD", "mysqladmin", "ping", "-p${DB_PASSWORD}"]
            retries: 3
            timeout: 5s
    redis:
        image: 'redis:alpine'
        ports:
            - '${FORWARD_REDIS_PORT:-6379}:6379'
        volumes:
            - 'sailredis:/data'
        networks:
            - sail
        healthcheck:
            test: ["CMD", "redis-cli", "ping"]
            retries: 3
            timeout: 5s
    meilisearch:
        image: 'getmeili/meilisearch:latest'
        platform: linux/x86_64
        ports:
            - '${FORWARD_MEILISEARCH_PORT:-7700}:7700'
        volumes:
            - 'sailmeilisearch:/data.ms'
        networks:
            - sail
        healthcheck:
            test: ["CMD", "wget", "--no-verbose", "--spider",  "http://localhost:7700/health"]
            retries: 3
            timeout: 5s
    mailhog:
        image: 'mailhog/mailhog:latest'
        ports:
            - '${FORWARD_MAILHOG_PORT:-1025}:1025'
            - '${FORWARD_MAILHOG_DASHBOARD_PORT:-8025}:8025'
        networks:
            - sail
    selenium:
        image: 'selenium/standalone-chrome'
        volumes:
            - '/dev/shm:/dev/shm'
        networks:
            - sail
networks:
    sail:
        driver: bridge
volumes:
    sailmysql:
        driver: local
    sailredis:
        driver: local
    sailmeilisearch:
        driver: local

stratboy's avatar

@Sinnbeck shown below. Should I maybe manually add the user (create user)? But if yes, where can I fine the host IP informations? Is the IP fixed/static for each container?

stratboy's avatar

@Sinnbeck

DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=testsite4
DB_USERNAME=sail
DB_PASSWORD=
Sinnbeck's avatar

@stratboy It should be automatically added when your create container the first time. It creates a volume where the data is saved. I honestly cant think of reason why deleting the volume didn't work. I google a bit and people tend to agree that the solution I suggested is how you rebuild it.

https://stackoverflow.com/a/65607826/1305117

stratboy's avatar

@Sinnbeck I know, but here doesn't work. Probably I'll go back to mamp or valet. Quite disappointed though (not with you all, obviously, but with Laravel), because Docker is currently presented as the easier, zero config solution. It's not, not in every case. I found several posts on google about people struggling with my very same issues (and stil I didn't find any solution anyway). So I should study Docker from the inside, which definitely it's not what's supposed to be done by a guy trying to learn Laravel (and not Docker). It's simply a pity, in my own opition..

stratboy's avatar

@Sinnbeck Hi! I finally managed to get it working. I really don't know what was the problem. I just tried to completely delete the container and reinstall everything again on another folder, starting again with curl -s "https://laravel.build/example-app" | bash and all went fine for now, migrations included.

Thank you anyway for all your support.

martinbean's avatar

@stratboy If you’re using a container then you’ll need to run the command inside the container; not from your computer.

stratboy's avatar

@martinbean What do you mean? I click the cli from php image in Docker, but when running migrations I get the same error above.

martinbean's avatar

@stratboy Because the version of PHP in a Docker image might be different to the version of PHP installed on your computer, hence the version mismatch error.

stratboy's avatar

@martinbean ok but I was doing it from the container. Anyway, by resetting a few thing I got php right, now I have a problem with db access :)

Please or to participate in this conversation.