★環境
ベースOS:Windows11
Linux用Windowsサブシステム:WSL2(Windows Subsystem for Linux 2)
Linux:Ubuntu-20.04
仮想コンテナ:Docker Desktop 4.30.0 (149282)
移行というよりは、開発環境の変更なので、WSLを使って開発領域にgitでリポジトリをダウンロードし、そこにLaravel Sailをインストールする。
後は必要なLaravelのパッケージやデータベースなどを復元する。
①WSLの開発領域にgitからリポジトリから取得
git clone https://github.com/<アカウント名>/<リポジトリ名>.git
Cloning into 'Lara-Tech'...
remote: Enumerating objects: 1581, done.
remote: Counting objects: 100% (132/132), done.
remote: Compressing objects: 100% (81/81), done.
remote: Total 1581 (delta 69), reused 96 (delta 49), pack-reused 1449
Receiving objects: 100% (1581/1581), 2.86 MiB | 6.28 MiB/s, done.
Resolving deltas: 100% (838/838), done.
Updating files: 100% (350/350), done.
②composerでLaravelをインストール
root@wsl:/home/Lara-Tech# composer install
Do not run Composer as root/super user! See https://getcomposer.org/root for details
Continue as root/super user [yes]? yes
Installing dependencies from lock file (including require-dev)
Verifying lock file contents can be installed on current platform.
Package operations: 121 installs, 0 updates, 0 removals
- Downloading symfony/polyfill-iconv (v1.28.0)
- Downloading dasprid/enum (1.0.5)
.
.
.
<中略>
.
.
.
Package manifest generated successfully.
80 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
③npmをインストール
root@wsl:/home/Lara-Tech# npm install
npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
npm WARN deprecated uuid@3.4.0: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details.
npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
npm WARN deprecated querystring@0.2.0: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
npm WARN deprecated popper.js@1.16.1: You can find the new Popper v2 at @popperjs/core, this package is dedicated to the legacy v1
added 888 packages, and audited 889 packages in 22s
92 packages are looking for funding
run `npm fund` for details
30 vulnerabilities (2 low, 5 moderate, 18 high, 5 critical)
To address all issues, run:
npm audit fix
Run `npm audit` for details.
④Laravel Sailをインストール
root@wsl:/home/Lara-Tech# composer require laravel/sail --dev
Do not run Composer as root/super user! See https://getcomposer.org/root for details
Continue as root/super user [yes]? yes
./composer.json has been updated
Running composer update laravel/sail
Loading composer repositories with package information
Updating dependencies
Nothing to modify in lock file
Writing lock file
Installing dependencies from lock file (including require-dev)
Nothing to install, update or remove
Package fruitcake/laravel-cors is abandoned, you should avoid using it. No replacement was suggested.
Package laravelcollective/html is abandoned, you should avoid using it. Use spatie/laravel-html instead.
Package laravelium/sitemap is abandoned, you should avoid using it. No replacement was suggested.
Package swiftmailer/swiftmailer is abandoned, you should avoid using it. Use symfony/mailer instead.
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi
Discovered Package: facade/ignition
Discovered Package: fruitcake/laravel-cors
Discovered Package: jenssegers/agent
Discovered Package: laravel/fortify
Discovered Package: laravel/jetstream
Discovered Package: laravel/sail
Discovered Package: laravel/sanctum
Discovered Package: laravel/tinker
Discovered Package: laravel/ui
Discovered Package: laravelcollective/html
Discovered Package: laravelium/sitemap
Discovered Package: livewire/livewire
Discovered Package: nesbot/carbon
Discovered Package: nunomaduro/collision
Package manifest generated successfully.
80 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
No publishable resources for tag [laravel-assets].
Publishing complete.
No security vulnerability advisories found.
Using version ^1.25 for laravel/sail
⑤Laravel Sailのセットアップ
root@wsl:/home/Lara-Tech# php artisan sail:install
Which services would you like to install? [mysql]:
[0] mysql
[1] pgsql
[2] mariadb
[3] redis
[4] memcached
[5] meilisearch
[6] minio
[7] mailpit
[8] selenium
[9] soketi
>
Sail scaffolding installed successfully.
[+] Pulling 1/1
✔ mysql Pulled 2.5s
Sail images installed successfully.
[+] Building 8.0s (5/16) docker:default
=> [laravel.test internal] load .dockerignore 0.1s
=> => transferring context: 2B 0.0s
=> [laravel.test internal] load build definition from Dockerfile 0.1s
=> => transferring dockerfile: 3.09kB 0.0s
=> [laravel.test internal] load metadata for docker.io/library/ubuntu:22.04 2.6s
=> [laravel.test auth] library/ubuntu:pull token for registry-1.docker.io 0.0s
=> [laravel.test 1/11] FROM docker.io/library/ubuntu:22.04@sha256:a6d2b38300ce017add71440577d5b0a90460d0e57fd7aec21dd0d1b0761bbfb2 5.3s
[+] Building 8.2s (5/16) docker:default
=> [laravel.test internal] load .dockerignore 0.1s
=> => transferring context: 2B 0.0s
=> [laravel.test internal] load build definition from Dockerfile 0.1s
=> => transferring dockerfile: 3.09kB 0.0s
=> [laravel.test internal] load metadata for docker.io/library/ubuntu:22.04 2.6s
=> [laravel.test auth] library/ubuntu:pull token for registry-1.docker.io 0.0s
=> [laravel.test 1/11] FROM docker.io/library/ubuntu:22.04@sha256:a6d2b38300ce017add71440577d5b0a90460d0e57fd7aec21dd0d1b0761bbfb2 5.5s
[+] Building 304.7s (17/17) FINISHED docker:default
=> [laravel.test internal] load .dockerignore 0.1s
=> => transferring context: 2B 0.0s
=> [laravel.test internal] load build definition from Dockerfile 0.1s
=> => transferring dockerfile: 3.09kB 0.0s
=> [laravel.test internal] load metadata for docker.io/library/ubuntu:22.04 2.6s
=> [laravel.test auth] library/ubuntu:pull token for registry-1.docker.io 0.0s
=> [laravel.test 1/11] FROM docker.io/library/ubuntu:22.04@sha256:a6d2b38300ce017add71440577d5b0a90460d0e57fd7aec21dd0d1b0761bbfb2 6.0s
=> => resolve docker.io/library/ubuntu:22.04@sha256:a6d2b38300ce017add71440577d5b0a90460d0e57fd7aec21dd0d1b0761bbfb2 0.0s
=> => sha256:52882761a72a60649edff9a2478835325d084fb640ea32a975e29e12a012025f 2.30kB / 2.30kB 0.0s
=> => sha256:a8b1c5f80c2d2a757adc963e3fe2dad0b4d229f83df3349fbb70e4d12dd48822 29.53MB / 29.53MB 3.0s
=> => sha256:a6d2b38300ce017add71440577d5b0a90460d0e57fd7aec21dd0d1b0761bbfb2 1.13kB / 1.13kB 0.0s
=> => sha256:2af372c1e2645779643284c7dc38775e3dbbc417b2d784a27c5a9eb784014fb8 424B / 424B 0.0s
=> => extracting sha256:a8b1c5f80c2d2a757adc963e3fe2dad0b4d229f83df3349fbb70e4d12dd48822 2.7s
=> [laravel.test internal] load build context 0.1s
=> => transferring context: 907B 0.0s
=> [laravel.test 2/11] WORKDIR /var/www/html 1.2s
=> [laravel.test 3/11] RUN ln -snf /usr/share/zoneinfo/UTC /etc/localtime && echo UTC > /etc/timezone 0.5s
=> [laravel.test 4/11] RUN apt-get update && mkdir -p /etc/apt/keyrings && apt-get install -y gnupg gosu curl ca-certificates zip unzip git supervisor sqlite3 284.1s
=> [laravel.test 5/11] RUN setcap "cap_net_bind_service=+ep" /usr/bin/php8.2 0.5s
=> [laravel.test 6/11] RUN groupadd --force -g 0 sail 0.6s
=> [laravel.test 7/11] RUN useradd -ms /bin/bash --no-user-group -g 0 -u 1337 sail 0.6s
=> [laravel.test 8/11] COPY start-container /usr/local/bin/start-container 0.0s
=> [laravel.test 9/11] COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf 0.0s
=> [laravel.test 10/11] COPY php.ini /etc/php/8.2/cli/conf.d/99-sail.ini 0.0s
=> [laravel.test 11/11] RUN chmod +x /usr/local/bin/start-container 0.5s
=> [laravel.test] exporting to image 7.6s
=> => exporting layers 7.6s
=> => writing image sha256:871980806632684996061e01e3265b162e73f6f8572b2821c1e07986f9cfbdb5 0.0s
=> => naming to sail-8.2/app 0.0s
Sail build successful.
⑥プロジェクトに書き込み権限の付与
root@wsl:/home/Lara-Tech# chmod -R 777 .*
⑦docker-compose.ymlを変更(必要なものを揃える)
services:
laravel.test:
build:
context: ./vendor/laravel/sail/runtimes/8.2
dockerfile: Dockerfile
args:
WWWGROUP: '${WWWGROUP}'
image: sail-8.2/app
extra_hosts:
- 'host.docker.internal:host-gateway'
ports:
- '${APP_PORT:-80}:80'
- '${VITE_PORT:-5173}:${VITE_PORT:-5173}'
environment:
WWWUSER: '${WWWUSER}'
LARAVEL_SAIL: 1
XDEBUG_MODE: '${SAIL_XDEBUG_MODE:-off}'
XDEBUG_CONFIG: '${SAIL_XDEBUG_CONFIG:-client_host=host.docker.internal}'
IGNITION_LOCAL_SITES_PATH: '${PWD}'
volumes:
- '.:/var/www/html'
networks:
- sail
depends_on:
- mysql
mysql:
image: 'mysql/mysql-server:8.0'
ports:
- '${FORWARD_DB_PORT:-3306}:3306'
environment:
MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}'
MYSQL_ROOT_HOST: '%'
MYSQL_DATABASE: '${DB_DATABASE}'
MYSQL_USER: '${DB_USERNAME}'
MYSQL_PASSWORD: '${DB_PASSWORD}'
MYSQL_ALLOW_EMPTY_PASSWORD: 1
volumes:
- 'sail-mysql:/var/lib/mysql'
- './docker/mysql/create-testing-database.sh:/docker-entrypoint-initdb.d/10-create-testing-database.sh'
networks:
- sail
healthcheck:
test:
- CMD
- mysqladmin
- ping
- '-p${DB_PASSWORD}'
retries: 3
timeout: 5s
phpmyadmin:
image: phpmyadmin/phpmyadmin
links:
- mysql:mysql
ports:
- "8080:80"
environment:
MYSQL_USERNAME: '${DB_USERNAME}'
MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}'
PMA_HOST: mysql
UPLOAD_LIMIT: 100M
networks:
- sail
networks:
sail:
driver: bridge
volumes:
sail-mysql:
driver: local
⑧DBを再構築
sail環境の場合「php artisan migrate」ではエラーになる可能性あるためsailで実行する
———-
root@wsl:/home/Lara-Tech# php artisan migrate
Illuminate\Database\QueryException
could not find driver (SQL: select * from information_schema.tables where table_schema = ***** and table_name = migrations and table_type = ‘BASE TABLE’)
at vendor/laravel/framework/src/Illuminate/Database/Connection.php:712
708▕ // If an exception occurs when attempting to run a query, we’ll format the error
709▕ // message to include the bindings with SQL, which will make this exception a
710▕ // lot more helpful to the developer instead of just the database’s errors.
711▕ catch (Exception $e) {
➜ 712▕ throw new QueryException(
713▕ $query, $this->prepareBindings($bindings), $e
714▕ );
715▕ }
716▕ }
+33 vendor frames
34 artisan:35
Illuminate\Foundation\Console\Kernel::handle()
⑨Sailを実行
root@wsl:/home/Lara-Tech# sail up -d
基本的には「sail up -d」で実行出来ない場合はビルドを実行
———-
root@wsl:/home/Lara-Tech# sail build –no-cache
コメント