はじめに
当方のメインサイトはLaravelで作られているのですが、トップページに1行しか無い寂しいサイト。そろそろ本格的に作ろうということでしたが、結構色々ありまして…最初、laravel/uiをインストールしようとしたら、laravelのバージョンが古すぎて入れないというのがきっかけで、バージョンアップしようということにしました。
背景
当方のサイトは、開発環境としてローカルマシン上でDockerを使って構築、本番環境にGithub(プライベートリポジトリ)を介して適応しています。
取り急ぎバージョンアップ
取り急ぎ着手しなければとなったのはLaravelのバージョン。
調べてみると、6.17という結構古いものでした。
root@78e089450650:/var/www# php artisan --version
Laravel Framework 6.17.1
Composerのアップデート
しかも、Composereを使ってみると「バージョンが古すぎる!」というメッセージが出ていました。
root@***:~# curl -sS https://getcomposer.org/installer | php
All settings correct for using Composer
Downloading...
Composer (version 1.10.15) successfully installed to: /root/composer.phar
Use it: php composer.phar
root@***:~# mv composer.phar /usr/local/bin/composer
root@***:~# composer --version
Composer version 1.10.15 2020-10-13 15:59:09
これで、Composerのアップデートが出来ました。
6.x -> 7.x へのバージョンアップ
基本的に、Qiitaの記事で書かれている内容で対応できました(サイトの中身がほとんど無いので変更点は少なかった模様)。
この記事を基にファイルを編集、composer update
かけることで7.xにアップデートできます。
root@***:/var/www# composer update
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 12 installs, 58 updates, 3 removals
- Removing symfony/debug (v4.4.4)
- Removing jakub-onderka/php-console-highlighter (v0.4)
- Removing jakub-onderka/php-console-color (v0.2)
:
Discovered Package: nesbot/carbon
Discovered Package: nunomaduro/collision
Package manifest generated successfully.
49 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
root@***:/var/www# php artisan --version
Laravel Framework 7.28.4
念の為、npm install
-> npm run dev
しておいたほうがいいと思います。
7.x -> 8.x へのバージョンアップ
基本的に、以下のサイトで書かれている内容で対応できました(サイトの中身がほとんどなかったため、composer.json
の依存性のみを設定すればOKでした)
root@***:/var/www# composer update
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 6 installs, 23 updates, 1 removal
- Removing phpunit/php-token-stream (3.1.1)
- Installing graham-campbell/result-type (v1.0.1): Downloading (100%)
- Updating vlucas/phpdotenv (v4.1.8 => v5.2.0): Downloading (100%)
:
Discovered Package: nesbot/carbon
Discovered Package: nunomaduro/collision
Package manifest generated successfully.
71 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
root@***:/var/www# php artisan --version
Laravel Framework 8.10.0
バージョンアップのコツ
対応を端折らずに、1バージョンずつ上げることをお勧めします(6.x -> 7.x -> 8.x)。
最後に
開発環境で動作を確認したら、Githubにソースをpush、本番環境でpullして composer update
-> npm install
-> npm run production
すれば、両方の環境でバージョンを揃えられると思います。