【问题标题】:Laravel Sail installing wrong PHP versionLaravel Sail 安装错误的 PHP 版本
【发布时间】:2026-02-13 23:35:01
【问题描述】:

我不明白为什么 Sail 安装的是 PHP 8.1 而不是 8.0。它暂时破坏了我的应用程序。

这是 docker-compose.yml:

# For more information: https://laravel.com/docs/sail
version: '3'
services:
    laravel.test:
        build:
            context: ./docker/8.0
            dockerfile: Dockerfile
            args:
                WWWGROUP: '${WWWGROUP}'
        image: sail-8.0/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
    
...


这是 Docker 文件:https://github.com/laravel/sail/blob/1.x/runtimes/8.0/Dockerfile

我已经重建了很多次图像,但我仍然得到这个:

sail@c5f380167b79:/var/www/html$ php -v
PHP 8.1.2 (cli) (built: Jan 24 2022 10:42:51) (NTS)

【问题讨论】:

标签: php docker dockerfile


【解决方案1】:

这有助于添加这一行:RUN update-alternatives --set php /usr/bin/php8.0

https://github.com/laravel/sail/commit/dbe4a908d254d91f99ed89047c9eec4bae8973b0

【讨论】:

  • 由于这个问题在 v1.13.1 中已修复,最好升级您的本地版本的 Sail
  • 我花了几个小时试图让我的项目启动并运行...感谢您告诉我们!