デプロイ先の環境に合わせるため Laravel Sail のPHPバージョンをPHP8.2からPHP8.0に変更する方法のメモ。
Laravel Sail PHPバージョン変更
変更前のPHPバージョン確認
% sail php -v PHP 8.2.1 (cli) (built: Jan 6 2023 15:18:43) (NTS) Copyright (c) The PHP Group Zend Engine v4.2.1, Copyright (c) Zend Technologies with Zend OPcache v8.2.1, Copyright (c), by Zend Technologies with Xdebug v3.2.0, Copyright (c) 2002-2022, by Derick Rethans
docker-compose.yml修正
laravel.test の build と image のバージョン情報を 8.2 から 8.0 へ修正します
# docker-compose.yml
laravel.test:
build:
context: ./vendor/laravel/sail/runtimes/8.0
dockerfile: Dockerfile
args:
WWWGROUP: '${WWWGROUP}'
image: sail-8.0/app
コンテナイメージ再構築
% sail build --no-cache [+] Building 276.4s (17/17) FINISHED => [internal] load build definition from Dockerfile 0.1s => => transferring dockerfile: 2.82kB 0.0s => [internal] load .dockerignore 0.0s => => transferring context: 2B 0.0s => [internal] load metadata for docker.io/library/ubuntu:20.04 4.4s => [ 1/12] FROM docker.io/library/ubuntu:20.04@sha256:4a45212e9518f35983a976eead0de5eecc555a2f047134e9dd2cfc589076a00d 8.5s => => resolve docker.io/library/ubuntu:20.04@sha256:4a45212e9518f35983a976eead0de5eecc555a2f047134e9dd2cfc589076a00d 0.0s => => sha256:b549f31133a955f68f9fa0d93f18436c4a180e12184b999a8ecf14f7eaa83309 27.50MB / 27.50MB 6.9s => => sha256:4a45212e9518f35983a976eead0de5eecc555a2f047134e9dd2cfc589076a00d 1.13kB / 1.13kB 0.0s => => sha256:bffb6799d706144f263f4b91e1226745ffb5643ea0ea89c2f709208e8d70c999 424B / 424B 0.0s => => sha256:e40cf56b4be35b04f620bc9cfbef80038fd7370d4ed36d90676223174ecbf0b0 2.30kB / 2.30kB 0.0s => => extracting sha256:b549f31133a955f68f9fa0d93f18436c4a180e12184b999a8ecf14f7eaa83309 1.3s => [internal] load build context 0.0s => => transferring context: 986B 0.0s => [ 2/12] WORKDIR /var/www/html 0.3s => [ 3/12] RUN ln -snf /usr/share/zoneinfo/UTC /etc/localtime && echo UTC > /etc/timezone 0.3s => [ 4/12] RUN apt-get update && apt-get install -y gnupg gosu curl ca-certificates zip unzip git supervisor sqlite3 libcap2-bin libpng-dev python2 dnsuti 253.2s => [ 5/12] RUN update-alternatives --set php /usr/bin/php8.0 0.3s => [ 6/12] RUN setcap "cap_net_bind_service=+ep" /usr/bin/php8.0 0.3s => [ 7/12] RUN groupadd --force -g 20 sail 0.5s => [ 8/12] RUN useradd -ms /bin/bash --no-user-group -g 20 -u 1337 sail 0.4s => [ 9/12] COPY start-container /usr/local/bin/start-container 0.0s => [10/12] COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf 0.0s => [11/12] COPY php.ini /etc/php/8.0/cli/conf.d/99-sail.ini 0.0s => [12/12] RUN chmod +x /usr/local/bin/start-container 0.3s => exporting to image 7.6s => => exporting layers 7.6s => => writing image sha256:33a4eae05aa9ea1615bf22d43a8d2c1f4f134868f97195a9b2a8aac622413139 0.0s => => naming to sail-8.0/app
コンテナ起動
% sail up -d
PHPパッケージ更新
% sail composer update Loading composer repositories with package information Info from https://repo.packagist.org: #StandWithUkraine Updating dependencies Lock file operations: 2 installs, 23 updates, 0 removals - Locking doctrine/deprecations (v1.0.0) - Downgrading doctrine/instantiator (2.0.0 => 1.5.0) - Downgrading doctrine/lexer (3.0.0 => 2.1.0) - Downgrading egulias/email-validator (4.0.1 => 3.2.5) . . . - Downgrading symfony/translation-contracts (v3.2.0 => v3.0.2): Extracting archive - Downgrading symfony/translation (v6.2.5 => v6.0.19): Extracting archive - Downgrading doctrine/instantiator (2.0.0 => 1.5.0): Extracting archive Generating optimized autoload files > Illuminate\Foundation\ComposerScripts::postAutoloadDump > @php artisan package:discover --ansi INFO Discovering packages. laravel/breeze ................. DONE laravel/sail ................... DONE laravel/sanctum ................ DONE laravel/tinker ................. DONE nesbot/carbon .................. DONE nunomaduro/collision ........... DONE nunomaduro/termwind ............ DONE spatie/laravel-ignition ........ DONE 81 packages you are using are looking for funding. Use the `composer fund` command to find out more! > @php artisan vendor:publish --tag=laravel-assets --ansi --force INFO No publishable resources for tag [laravel-assets]. No security vulnerability advisories found
変更後のPHPバージョン確認
% sail php -v PHP 8.0.27 (cli) (built: Jan 13 2023 10:42:52) ( NTS ) Copyright (c) The PHP Group Zend Engine v4.0.27, Copyright (c) Zend Technologies with Zend OPcache v8.0.27, Copyright (c), by Zend Technologies with Xdebug v3.2.0, Copyright (c) 2002-2022, by Derick Rethans
動作環境情報
"macOS Ventura" 13.1 "Docker Desktop" 4.16.2 "Laravel Sail" "Laravel Framework" 9.50.2 "PHP" 8.0.27
コメント