sailを利用して作成した laravel 11 のプロジェクトをlaravel 12 にアップグレードします
アップグレード前のバージョンは以下です
root@3c55a90331b7:/var/www/html# php artisan -v
Laravel Framework 11.37.0
Usage:
command [options] [arguments]
sail を利用したプロジェクト作成方法は以下を参照しました
https://laravel.com/docs/12.x/sail#installing-sail-into-existing-applications
アップグレード手順
-
コンテナを削除する
-
アップグレードガイド1に沿って、composer.json を書き換え
"require": { "php": "^8.2", - "laravel/framework": "^11.31", + "laravel/framework": "^12.0",
-
sailコマンドで自動作成されたdockerfileは任意のフォルダ配下に退避しておく
mv ./vendor/laravel/sail/runtimes/8.4 ./infra/8.4 # 利用するdatabaseによって適宜変更してください mv ./vendor/laravel/sail/database/mysql/create-testing-database.sh ./infra/mysql/create-testing-database.sh
-
退避させたフォルダ配下にパスを書き換え
docker-compose.ymlservices: laravel.test: build: - context: './vendor/laravel/sail/runtimes/8.4' + context: './infra/8.4'
docker-compose.ymlmysql: volumes: - 'sail-mysql:/var/lib/mysql' - - './vendor/laravel/sail/database/mysql/create-testing-database.sh:/docker-entrypoint-initdb.d/10-create-testing-database.sh' + - './infra/mysql/create-testing-database.sh:/docker-entrypoint-initdb.d/10-create-testing-database.sh'
- ビルドイメージ名も合わせて変更しておく、イメージ名は任意
docker-compose.ymllaravel.test: build: context: './infra/8.4' dockerfile: Dockerfile args: WWWGROUP: '${WWWGROUP}' - image: 'sail-8.4/app' + image: 'laravel.test'
-
依存関係を再インストールするためにvendorフォルダを削除
-
Composer依存関係インストール
$ docker run --rm \ -u "$(id -u):$(id -g)" \ -v $(pwd):/opt \ -w /opt \ laravelsail/php82-composer:latest \ composer update && composer install --ignore-platform-reqs
直接composer.jsonを書き換えたので、
composer update
が必要です$ docker run --rm \ -u "$(id -u):$(id -g)" \ -v $(pwd):/opt \ -w /opt \ laravelsail/php82-composer:latest \ composer install --ignore-platform-reqs Installing dependencies from lock file (including require-dev) Verifying lock file contents can be installed on current platform. Warning: The lock file is not up to date with the latest changes in composer.json. You may be getting outdated dependencies. It is recommended that you run `composer update` or `composer update <package name>`. - Required package "laravel/framework" is in the lock file as "v11.37.0" but that does not satisfy your constraint "^12.0". This usually happens when composer files are incorrectly merged or the composer.json file is manually edited. Read more about correctly resolving merge conflicts https://getcomposer.org/doc/articles/resolving-merge-conflicts.md and prefer using the "require" command over editing the composer.json file directly https://getcomposer.org/doc/03-cli.md#require-r
-
コンテナ起動
sail up -d
-
バージョン確認
$ docker exec -it example-app-laravel.test-1 bash root@a3ed716ddcf8:/var/www/html# php artisan -v Laravel Framework 12.21.0 Usage: command [options] [arguments] ...以下省略