0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

sail で作成したlaravel 11 のプロジェクトを laravel 12 に アップグレードする

Posted at

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. コンテナを削除する

  2. アップグレードガイド1に沿って、composer.json を書き換え

        "require": {
            "php": "^8.2",
    -       "laravel/framework": "^11.31",
    +       "laravel/framework": "^12.0",
    
  3. 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
    
  4. 退避させたフォルダ配下にパスを書き換え

    docker-compose.yml
    services:
        laravel.test:
            build:
    -            context: './vendor/laravel/sail/runtimes/8.4'
    +            context: './infra/8.4'
    
    docker-compose.yml
        mysql:
            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.yml
        laravel.test:
            build:
                context: './infra/8.4'
                dockerfile: Dockerfile
                args:
                    WWWGROUP: '${WWWGROUP}'
    -        image: 'sail-8.4/app'
    +        image: 'laravel.test'
    
  5. 依存関係を再インストールするためにvendorフォルダを削除

  6. 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
    
  7. コンテナ起動

    sail up -d
    
  8. バージョン確認

    $ 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]
    ...以下省略
    
  1. https://laravel.com/docs/12.x/upgrade#upgrade-12.0

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?