何かかんかlaravel sailで最速開発セットアップしたい場合
dockerを入れてからの、やはりlaravel.buildを使うのが一番速いと思われる。
サービスの選択
基本今日日やはりRDBMSを使う事が多いのでmysqlとかはいれたいとかあると思うけど、実際はもっと細かく、以下の(docker)サービスを選択できる。
mysql
pgsql
mariadb
redis
memcached
meilisearch
minio
selenium
mailpit
上3つはRDBMSとしてそれ以降はAIの解説と供にお送りします
Redis:オープンソースのインメモリデータベースで、高速に動作することで知られています。データ構造サーバーとしても機能し、文字列、ハッシュ、リスト、セット、ソートされたセットといった高度なデータ構造をサポートします。また、パブリッシュ/サブスクライブの機能、トランザクション、持続性などの機能も備えています。
Memcached:分散型の高速なインメモリキャッシュシステムで、動的なWebアプリケーションの負荷を軽減するために使用されます。データベースの読み出し時間を短縮するために、一時的にデータをRAMに格納します。
MeiliSearch:高速な全文検索とインスタント検索体験を提供するオープンソースの検索エンジンです。これにより、ユーザーはリアルタイムで結果を取得しながら、検索語句を入力できます。
MinIO:高パフォーマンスで、スケーラビリティに優れたオブジェクトストレージシステムで、Amazon S3と互換性があります。プライベートクラウドやパブリッククラウドで使用するための、持続可能な、安全なストレージソリューションを提供します。
Selenium:ウェブブラウザーの自動化テストを支援するツールです。Seleniumは、様々なプログラミング言語(Java、C#、Python、Rubyなど)を使用してウェブアプリケーションのテストを作成し、任意のウェブブラウザーでこれらのテストを実行することを可能にします。
Mailpit:安全なSMTPサーバーとして設計されたサービスで、開発者が送信したメールをテストできるようにします。これにより、アプリケーションから送信されるメールのデザインや機能性を確認することができます。
ちなみに、mailhogはsail的にオワコンになっちゃったようだが、Mailpitは入れておくと便利な事も多いのでは。それ以外はあってもなくてもいいかって感じもするが、、という事で今回はmysqlとmailpitを入れるものとする、とすると以下のように引き込んでくる。
% curl -s "https://laravel.build/your_app_name?with=mysql,mailpit" | bash
今回は何となく記事カサ増しでログも書いちゃおうかな
% curl -s "https://laravel.build/your_app_name?with=mysql,mailpit" | bash
latest: Pulling from laravelsail/php82-composer
Digest: sha256:37549f980be6146efcb16b0dc352644edfc5cca32b9862494631eb197ef89737
Status: Image is up to date for laravelsail/php82-composer:latest
_ _
| | | |
| | __ _ _ __ __ ___ _____| |
| | / _` | '__/ _` \ \ / / _ \ |
| |___| (_| | | | (_| |\ V / __/ |
|______\__,_|_| \__,_| \_/ \___|_|
WARN TTY mode requires /dev/tty to be read/writable.
Creating a "laravel/laravel" project at "./your_app_name"
Info from https://repo.packagist.org: #StandWithUkraine
Installing laravel/laravel (v10.2.5)
- Downloading laravel/laravel (v10.2.5)
- Installing laravel/laravel (v10.2.5): Extracting archive
Created project in /opt/your_app_name
> @php -r "file_exists('.env') || copy('.env.example', '.env');"
Loading composer repositories with package information
Updating dependencies
Lock file operations: 109 installs, 0 updates, 0 removals
- Locking brick/math (0.11.0)
- Locking dflydev/dot-access-data (v3.0.2)
- Locking doctrine/inflector (2.0.8)
- Locking doctrine/lexer (3.0.0)
- Locking dragonmantank/cron-expression (v3.3.2)
- Locking egulias/email-validator (4.0.1)
- Locking fakerphp/faker (v1.23.0)
- Locking filp/whoops (2.15.3)
- Locking fruitcake/php-cors (v1.2.0)
- Locking graham-campbell/result-type (v1.1.1)
- Locking guzzlehttp/guzzle (7.7.0)
- Locking guzzlehttp/promises (2.0.1)
- Locking guzzlehttp/psr7 (2.6.0)
- Locking guzzlehttp/uri-template (v1.0.1)
- Locking hamcrest/hamcrest-php (v2.0.1)
- Locking laravel/framework (v10.17.1)
- Locking laravel/pint (v1.10.5)
- Locking laravel/prompts (v0.1.3)
- Locking laravel/sail (v1.23.1)
- Locking laravel/sanctum (v3.2.5)
- Locking laravel/serializable-closure (v1.3.1)
- Locking laravel/tinker (v2.8.1)
- Locking league/commonmark (2.4.0)
- Locking league/config (v1.2.0)
- Locking league/flysystem (3.15.1)
- Locking league/flysystem-local (3.15.0)
- Locking league/mime-type-detection (1.12.0)
- Locking mockery/mockery (1.6.4)
- Locking monolog/monolog (3.4.0)
- Locking myclabs/deep-copy (1.11.1)
- Locking nesbot/carbon (2.68.1)
- Locking nette/schema (v1.2.3)
- Locking nette/utils (v4.0.1)
- Locking nikic/php-parser (v4.16.0)
- Locking nunomaduro/collision (v7.8.0)
- Locking nunomaduro/termwind (v1.15.1)
- Locking phar-io/manifest (2.0.3)
- Locking phar-io/version (3.2.1)
- Locking phpoption/phpoption (1.9.1)
- Locking phpunit/php-code-coverage (10.1.3)
- Locking phpunit/php-file-iterator (4.0.2)
- Locking phpunit/php-invoker (4.0.0)
- Locking phpunit/php-text-template (3.0.0)
- Locking phpunit/php-timer (6.0.0)
- Locking phpunit/phpunit (10.3.1)
- Locking psr/container (2.0.2)
- Locking psr/event-dispatcher (1.0.0)
- Locking psr/http-client (1.0.2)
- Locking psr/http-factory (1.0.2)
- Locking psr/http-message (2.0)
- Locking psr/log (3.0.0)
- Locking psr/simple-cache (3.0.0)
- Locking psy/psysh (v0.11.20)
- Locking ralouphie/getallheaders (3.0.3)
- Locking ramsey/collection (2.0.0)
- Locking ramsey/uuid (4.7.4)
- Locking sebastian/cli-parser (2.0.0)
- Locking sebastian/code-unit (2.0.0)
- Locking sebastian/code-unit-reverse-lookup (3.0.0)
- Locking sebastian/comparator (5.0.0)
- Locking sebastian/complexity (3.0.0)
- Locking sebastian/diff (5.0.3)
- Locking sebastian/environment (6.0.1)
- Locking sebastian/exporter (5.0.0)
- Locking sebastian/global-state (6.0.1)
- Locking sebastian/lines-of-code (2.0.0)
- Locking sebastian/object-enumerator (5.0.0)
- Locking sebastian/object-reflector (3.0.0)
- Locking sebastian/recursion-context (5.0.0)
- Locking sebastian/type (4.0.0)
- Locking sebastian/version (4.0.1)
- Locking spatie/backtrace (1.5.3)
- Locking spatie/flare-client-php (1.4.2)
- Locking spatie/ignition (1.9.0)
- Locking spatie/laravel-ignition (2.2.0)
- Locking symfony/console (v6.3.2)
- Locking symfony/css-selector (v6.3.2)
- Locking symfony/deprecation-contracts (v3.3.0)
- Locking symfony/error-handler (v6.3.2)
- Locking symfony/event-dispatcher (v6.3.2)
- Locking symfony/event-dispatcher-contracts (v3.3.0)
- Locking symfony/finder (v6.3.3)
- Locking symfony/http-foundation (v6.3.2)
- Locking symfony/http-kernel (v6.3.3)
- Locking symfony/mailer (v6.3.0)
- Locking symfony/mime (v6.3.3)
- Locking symfony/polyfill-ctype (v1.27.0)
- Locking symfony/polyfill-intl-grapheme (v1.27.0)
- Locking symfony/polyfill-intl-idn (v1.27.0)
- Locking symfony/polyfill-intl-normalizer (v1.27.0)
- Locking symfony/polyfill-mbstring (v1.27.0)
- Locking symfony/polyfill-php72 (v1.27.0)
- Locking symfony/polyfill-php80 (v1.27.0)
- Locking symfony/polyfill-php83 (v1.27.0)
- Locking symfony/polyfill-uuid (v1.27.0)
- Locking symfony/process (v6.3.2)
- Locking symfony/routing (v6.3.3)
- Locking symfony/service-contracts (v3.3.0)
- Locking symfony/string (v6.3.2)
- Locking symfony/translation (v6.3.3)
- Locking symfony/translation-contracts (v3.3.0)
- Locking symfony/uid (v6.3.0)
- Locking symfony/var-dumper (v6.3.3)
- Locking symfony/yaml (v6.3.3)
- Locking theseer/tokenizer (1.2.1)
- Locking tijsverkoyen/css-to-inline-styles (2.2.6)
- Locking vlucas/phpdotenv (v5.5.0)
- Locking voku/portable-ascii (2.0.1)
- Locking webmozart/assert (1.11.0)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 109 installs, 0 updates, 0 removals
- Downloading doctrine/inflector (2.0.8)
- Downloading doctrine/lexer (3.0.0)
- Downloading webmozart/assert (1.11.0)
- Downloading dragonmantank/cron-expression (v3.3.2)
- Downloading symfony/deprecation-contracts (v3.3.0)
- Downloading fakerphp/faker (v1.23.0)
- Downloading symfony/polyfill-php80 (v1.27.0)
- Downloading symfony/polyfill-php83 (v1.27.0)
- Downloading symfony/http-foundation (v6.3.2)
- Downloading fruitcake/php-cors (v1.2.0)
- Downloading psr/http-message (2.0)
- Downloading psr/http-client (1.0.2)
- Downloading ralouphie/getallheaders (3.0.3)
- Downloading psr/http-factory (1.0.2)
- Downloading guzzlehttp/psr7 (2.6.0)
- Downloading guzzlehttp/promises (2.0.1)
- Downloading guzzlehttp/guzzle (7.7.0)
- Downloading guzzlehttp/uri-template (v1.0.1)
- Downloading laravel/pint (v1.10.5)
- Downloading symfony/string (v6.3.2)
- Downloading symfony/service-contracts (v3.3.0)
- Downloading symfony/console (v6.3.2)
- Downloading voku/portable-ascii (2.0.1)
- Downloading phpoption/phpoption (1.9.1)
- Downloading graham-campbell/result-type (v1.1.1)
- Downloading vlucas/phpdotenv (v5.5.0)
- Downloading symfony/css-selector (v6.3.2)
- Downloading tijsverkoyen/css-to-inline-styles (2.2.6)
- Downloading symfony/var-dumper (v6.3.3)
- Downloading symfony/polyfill-uuid (v1.27.0)
- Downloading symfony/uid (v6.3.0)
- Downloading symfony/routing (v6.3.3)
- Downloading symfony/process (v6.3.2)
- Downloading symfony/polyfill-php72 (v1.27.0)
- Downloading symfony/polyfill-intl-idn (v1.27.0)
- Downloading symfony/mime (v6.3.3)
- Downloading psr/event-dispatcher (1.0.0)
- Downloading symfony/event-dispatcher-contracts (v3.3.0)
- Downloading symfony/event-dispatcher (v6.3.2)
- Downloading psr/log (3.0.0)
- Downloading egulias/email-validator (4.0.1)
- Downloading symfony/mailer (v6.3.0)
- Downloading symfony/error-handler (v6.3.2)
- Downloading symfony/http-kernel (v6.3.3)
- Downloading symfony/finder (v6.3.3)
- Downloading ramsey/collection (2.0.0)
- Downloading brick/math (0.11.0)
- Downloading ramsey/uuid (4.7.4)
- Downloading psr/simple-cache (3.0.0)
- Downloading nunomaduro/termwind (v1.15.1)
- Downloading symfony/translation-contracts (v3.3.0)
- Downloading symfony/translation (v6.3.3)
- Downloading nesbot/carbon (2.68.1)
- Downloading monolog/monolog (3.4.0)
- Downloading league/mime-type-detection (1.12.0)
- Downloading league/flysystem (3.15.1)
- Downloading league/flysystem-local (3.15.0)
- Downloading nette/utils (v4.0.1)
- Downloading nette/schema (v1.2.3)
- Downloading dflydev/dot-access-data (v3.0.2)
- Downloading league/config (v1.2.0)
- Downloading league/commonmark (2.4.0)
- Downloading laravel/serializable-closure (v1.3.1)
- Downloading laravel/prompts (v0.1.3)
- Downloading laravel/framework (v10.17.1)
- Downloading symfony/yaml (v6.3.3)
- Downloading laravel/sail (v1.23.1)
- Downloading laravel/sanctum (v3.2.5)
- Downloading nikic/php-parser (v4.16.0)
- Downloading psy/psysh (v0.11.20)
- Downloading laravel/tinker (v2.8.1)
- Downloading hamcrest/hamcrest-php (v2.0.1)
- Downloading mockery/mockery (1.6.4)
- Downloading filp/whoops (2.15.3)
- Downloading nunomaduro/collision (v7.8.0)
- Downloading sebastian/version (4.0.1)
- Downloading sebastian/type (4.0.0)
- Downloading sebastian/recursion-context (5.0.0)
- Downloading sebastian/object-reflector (3.0.0)
- Downloading sebastian/object-enumerator (5.0.0)
- Downloading sebastian/global-state (6.0.1)
- Downloading sebastian/exporter (5.0.0)
- Downloading sebastian/environment (6.0.1)
- Downloading sebastian/diff (5.0.3)
- Downloading sebastian/comparator (5.0.0)
- Downloading sebastian/code-unit (2.0.0)
- Downloading sebastian/cli-parser (2.0.0)
- Downloading phpunit/php-timer (6.0.0)
- Downloading phpunit/php-text-template (3.0.0)
- Downloading phpunit/php-invoker (4.0.0)
- Downloading phpunit/php-file-iterator (4.0.2)
- Downloading sebastian/lines-of-code (2.0.0)
- Downloading sebastian/complexity (3.0.0)
- Downloading sebastian/code-unit-reverse-lookup (3.0.0)
- Downloading phpunit/php-code-coverage (10.1.3)
- Downloading myclabs/deep-copy (1.11.1)
- Downloading phpunit/phpunit (10.3.1)
- Downloading spatie/backtrace (1.5.3)
- Downloading spatie/flare-client-php (1.4.2)
- Downloading spatie/ignition (1.9.0)
- Downloading spatie/laravel-ignition (2.2.0)
- Installing doctrine/inflector (2.0.8): Extracting archive
- Installing doctrine/lexer (3.0.0): Extracting archive
- Installing symfony/polyfill-ctype (v1.27.0): Extracting archive
- Installing webmozart/assert (1.11.0): Extracting archive
- Installing dragonmantank/cron-expression (v3.3.2): Extracting archive
- Installing symfony/deprecation-contracts (v3.3.0): Extracting archive
- Installing psr/container (2.0.2): Extracting archive
- Installing fakerphp/faker (v1.23.0): Extracting archive
- Installing symfony/polyfill-php80 (v1.27.0): Extracting archive
- Installing symfony/polyfill-php83 (v1.27.0): Extracting archive
- Installing symfony/polyfill-mbstring (v1.27.0): Extracting archive
- Installing symfony/http-foundation (v6.3.2): Extracting archive
- Installing fruitcake/php-cors (v1.2.0): Extracting archive
- Installing psr/http-message (2.0): Extracting archive
- Installing psr/http-client (1.0.2): Extracting archive
- Installing ralouphie/getallheaders (3.0.3): Extracting archive
- Installing psr/http-factory (1.0.2): Extracting archive
- Installing guzzlehttp/psr7 (2.6.0): Extracting archive
- Installing guzzlehttp/promises (2.0.1): Extracting archive
- Installing guzzlehttp/guzzle (7.7.0): Extracting archive
- Installing guzzlehttp/uri-template (v1.0.1): Extracting archive
- Installing laravel/pint (v1.10.5): Extracting archive
- Installing symfony/polyfill-intl-normalizer (v1.27.0): Extracting archive
- Installing symfony/polyfill-intl-grapheme (v1.27.0): Extracting archive
- Installing symfony/string (v6.3.2): Extracting archive
- Installing symfony/service-contracts (v3.3.0): Extracting archive
- Installing symfony/console (v6.3.2): Extracting archive
- Installing voku/portable-ascii (2.0.1): Extracting archive
- Installing phpoption/phpoption (1.9.1): Extracting archive
- Installing graham-campbell/result-type (v1.1.1): Extracting archive
- Installing vlucas/phpdotenv (v5.5.0): Extracting archive
- Installing symfony/css-selector (v6.3.2): Extracting archive
- Installing tijsverkoyen/css-to-inline-styles (2.2.6): Extracting archive
- Installing symfony/var-dumper (v6.3.3): Extracting archive
- Installing symfony/polyfill-uuid (v1.27.0): Extracting archive
- Installing symfony/uid (v6.3.0): Extracting archive
- Installing symfony/routing (v6.3.3): Extracting archive
- Installing symfony/process (v6.3.2): Extracting archive
- Installing symfony/polyfill-php72 (v1.27.0): Extracting archive
- Installing symfony/polyfill-intl-idn (v1.27.0): Extracting archive
- Installing symfony/mime (v6.3.3): Extracting archive
- Installing psr/event-dispatcher (1.0.0): Extracting archive
- Installing symfony/event-dispatcher-contracts (v3.3.0): Extracting archive
- Installing symfony/event-dispatcher (v6.3.2): Extracting archive
- Installing psr/log (3.0.0): Extracting archive
- Installing egulias/email-validator (4.0.1): Extracting archive
- Installing symfony/mailer (v6.3.0): Extracting archive
- Installing symfony/error-handler (v6.3.2): Extracting archive
- Installing symfony/http-kernel (v6.3.3): Extracting archive
- Installing symfony/finder (v6.3.3): Extracting archive
- Installing ramsey/collection (2.0.0): Extracting archive
- Installing brick/math (0.11.0): Extracting archive
- Installing ramsey/uuid (4.7.4): Extracting archive
- Installing psr/simple-cache (3.0.0): Extracting archive
- Installing nunomaduro/termwind (v1.15.1): Extracting archive
- Installing symfony/translation-contracts (v3.3.0): Extracting archive
- Installing symfony/translation (v6.3.3): Extracting archive
- Installing nesbot/carbon (2.68.1): Extracting archive
- Installing monolog/monolog (3.4.0): Extracting archive
- Installing league/mime-type-detection (1.12.0): Extracting archive
- Installing league/flysystem (3.15.1): Extracting archive
- Installing league/flysystem-local (3.15.0): Extracting archive
- Installing nette/utils (v4.0.1): Extracting archive
- Installing nette/schema (v1.2.3): Extracting archive
- Installing dflydev/dot-access-data (v3.0.2): Extracting archive
- Installing league/config (v1.2.0): Extracting archive
- Installing league/commonmark (2.4.0): Extracting archive
- Installing laravel/serializable-closure (v1.3.1): Extracting archive
- Installing laravel/prompts (v0.1.3): Extracting archive
- Installing laravel/framework (v10.17.1): Extracting archive
- Installing symfony/yaml (v6.3.3): Extracting archive
- Installing laravel/sail (v1.23.1): Extracting archive
- Installing laravel/sanctum (v3.2.5): Extracting archive
- Installing nikic/php-parser (v4.16.0): Extracting archive
- Installing psy/psysh (v0.11.20): Extracting archive
- Installing laravel/tinker (v2.8.1): Extracting archive
- Installing hamcrest/hamcrest-php (v2.0.1): Extracting archive
- Installing mockery/mockery (1.6.4): Extracting archive
- Installing filp/whoops (2.15.3): Extracting archive
- Installing nunomaduro/collision (v7.8.0): Extracting archive
- Installing sebastian/version (4.0.1): Extracting archive
- Installing sebastian/type (4.0.0): Extracting archive
- Installing sebastian/recursion-context (5.0.0): Extracting archive
- Installing sebastian/object-reflector (3.0.0): Extracting archive
- Installing sebastian/object-enumerator (5.0.0): Extracting archive
- Installing sebastian/global-state (6.0.1): Extracting archive
- Installing sebastian/exporter (5.0.0): Extracting archive
- Installing sebastian/environment (6.0.1): Extracting archive
- Installing sebastian/diff (5.0.3): Extracting archive
- Installing sebastian/comparator (5.0.0): Extracting archive
- Installing sebastian/code-unit (2.0.0): Extracting archive
- Installing sebastian/cli-parser (2.0.0): Extracting archive
- Installing phpunit/php-timer (6.0.0): Extracting archive
- Installing phpunit/php-text-template (3.0.0): Extracting archive
- Installing phpunit/php-invoker (4.0.0): Extracting archive
- Installing phpunit/php-file-iterator (4.0.2): Extracting archive
- Installing theseer/tokenizer (1.2.1): Extracting archive
- Installing sebastian/lines-of-code (2.0.0): Extracting archive
- Installing sebastian/complexity (3.0.0): Extracting archive
- Installing sebastian/code-unit-reverse-lookup (3.0.0): Extracting archive
- Installing phpunit/php-code-coverage (10.1.3): Extracting archive
- Installing phar-io/version (3.2.1): Extracting archive
- Installing phar-io/manifest (2.0.3): Extracting archive
- Installing myclabs/deep-copy (1.11.1): Extracting archive
- Installing phpunit/phpunit (10.3.1): Extracting archive
- Installing spatie/backtrace (1.5.3): Extracting archive
- Installing spatie/flare-client-php (1.4.2): Extracting archive
- Installing spatie/ignition (1.9.0): Extracting archive
- Installing spatie/laravel-ignition (2.2.0): Extracting archive
55 package suggestions were added by new dependencies, use `composer suggest` to see details.
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi
INFO Discovering packages.
laravel/sail .......................................................... DONE
laravel/sanctum ....................................................... DONE
laravel/tinker ........................................................ DONE
nesbot/carbon ......................................................... DONE
nunomaduro/collision .................................................. DONE
nunomaduro/termwind ................................................... DONE
spatie/laravel-ignition ............................................... DONE
82 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 artisan key:generate --ansi
INFO Application key set successfully.
INFO Application ready! Build something amazing.
Sail scaffolding installed successfully.
WARN TTY mode requires /dev/tty to be read/writable.
Pulling mysql ... done
Pulling mailpit ... done
mysql uses an image, skipping
mailpit uses an image, skipping
Building laravel.test
Step 1/19 : FROM ubuntu:22.04
---> cfb01e8e3121
Step 2/19 : LABEL maintainer="Taylor Otwell"
---> Using cache
---> 0e022a591efb
Step 3/19 : ARG WWWGROUP
---> Using cache
---> 9519a25fa89d
Step 4/19 : ARG NODE_VERSION=18
---> Using cache
---> 037a8a496278
Step 5/19 : ARG POSTGRES_VERSION=15
---> Using cache
---> 96a922699347
Step 6/19 : WORKDIR /var/www/html
---> Using cache
---> d51f1e5eb18e
Step 7/19 : ENV DEBIAN_FRONTEND noninteractive
---> Using cache
---> 5b0a0a6a64d6
Step 8/19 : ENV TZ=UTC
---> Using cache
---> a08c0072df18
Step 9/19 : RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
---> Using cache
---> cee1bd89f189
Step 10/19 : RUN apt-get update && apt-get install -y gnupg gosu curl ca-certificates zip unzip git supervisor sqlite3 libcap2-bin libpng-dev python2 dnsutils librsvg2-bin && curl -sS 'https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x14aa40ec0831756756d7f66c4f4ea0aae5267a6c' | gpg --dearmor | tee /etc/apt/keyrings/ppa_ondrej_php.gpg > /dev/null && echo "deb [signed-by=/etc/apt/keyrings/ppa_ondrej_php.gpg] https://ppa.launchpadcontent.net/ondrej/php/ubuntu jammy main" > /etc/apt/sources.list.d/ppa_ondrej_php.list && apt-get update && apt-get install -y php8.2-cli php8.2-dev php8.2-pgsql php8.2-sqlite3 php8.2-gd php8.2-imagick php8.2-curl php8.2-imap php8.2-mysql php8.2-mbstring php8.2-xml php8.2-zip php8.2-bcmath php8.2-soap php8.2-intl php8.2-readline php8.2-ldap php8.2-msgpack php8.2-igbinary php8.2-redis php8.2-swoole php8.2-memcached php8.2-pcov php8.2-xdebug && curl -sLS https://getcomposer.org/installer | php -- --install-dir=/usr/bin/ --filename=composer && curl -sLS https://deb.nodesource.com/setup_$NODE_VERSION.x | bash - && apt-get install -y nodejs && npm install -g npm && curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --dearmor | tee /etc/apt/keyrings/yarn.gpg >/dev/null && echo "deb [signed-by=/etc/apt/keyrings/yarn.gpg] https://dl.yarnpkg.com/debian/ stable main" > /etc/apt/sources.list.d/yarn.list && curl -sS https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor | tee /etc/apt/keyrings/pgdg.gpg >/dev/null && echo "deb [signed-by=/etc/apt/keyrings/pgdg.gpg] http://apt.postgresql.org/pub/repos/apt jammy-pgdg main" > /etc/apt/sources.list.d/pgdg.list && apt-get update && apt-get install -y yarn && apt-get install -y mysql-client && apt-get install -y postgresql-client-$POSTGRES_VERSION && apt-get -y autoremove && apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
---> Using cache
---> f88e9dea192b
Step 11/19 : RUN setcap "cap_net_bind_service=+ep" /usr/bin/php8.2
---> Using cache
---> 5332929bce41
Step 12/19 : RUN groupadd --force -g $WWWGROUP sail
---> Using cache
---> 6de94c3a7fb9
Step 13/19 : RUN useradd -ms /bin/bash --no-user-group -g $WWWGROUP -u 1337 sail
---> Using cache
---> d110a55b1b88
Step 14/19 : COPY start-container /usr/local/bin/start-container
---> Using cache
---> 27eed83687ba
Step 15/19 : COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
---> Using cache
---> e61157ffd288
Step 16/19 : COPY php.ini /etc/php/8.2/cli/conf.d/99-sail.ini
---> Using cache
---> 30a783d2b5de
Step 17/19 : RUN chmod +x /usr/local/bin/start-container
---> Using cache
---> d3e25a36af0c
Step 18/19 : EXPOSE 8000
---> Using cache
---> 2460991ddeb9
Step 19/19 : ENTRYPOINT ["start-container"]
---> Using cache
---> 6bc09cef7ff8
Successfully built 6bc09cef7ff8
Successfully tagged sail-8.2/app:latest
Get started with: cd your_app_name && ./vendor/bin/sail up
(23/08/05時点)
your_app_nameの所は好きな名前にすればそうやってディレクトリが作られますよ。
gitのimport
どのみち今日日はgitで作業する事になるんだろうから、ここにimportしておく。リモートのレポジトリがあるパターンがほとんどだと思うので。
.env.exampleについて
sailをinstallすると.envが独自に生成されるがこれはsail用となっており、.env.exampleとは設定が異なるものだ。
% diff -u .env .env.example
--- .env 2023-08-05 01:29:45.473129002 +0000
+++ .env.example 2023-08-05 01:29:45.329132132 +0000
@@ -1,6 +1,6 @@
APP_NAME=Laravel
APP_ENV=local
-APP_KEY=base64:mFIHeMjdww3lrEi8ZMEpOTlG9sRyJLoutSL93a1OUMs=
+APP_KEY=
APP_DEBUG=true
APP_URL=http://localhost
@@ -9,11 +9,11 @@
LOG_LEVEL=debug
DB_CONNECTION=mysql
-DB_HOST=mysql
+DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=your_app_name
-DB_USERNAME=sail
-DB_PASSWORD=password
+DB_USERNAME=root
+DB_PASSWORD=
BROADCAST_DRIVER=log
CACHE_DRIVER=file
開発用途だとこっちのDB設定の方が楽なのでここのDB設定はコピーしておいた方がいいかも。APP_KEYは何だかんだ毎回key:generateした方がいいかもですね。
importしていく
% git init
% git add .
% git commit -m "Initial commit"
% git remote add origin https://server/your_repos.git
% git push -u origin master # ここは最近mainになってる場合も多いから注意する事
取り直す
どうせ、作業を別環境で始める場合cloneする所からになるので、だったら最初からやってしまえという事で。
% git clone https://server/your_repos.git
cloneしたreposから使う手順
まず、vendor/ 以下laravel含めて何も入ってないので、composer installする必要がある。システムにcomposerが無い場合もあるだろうから、その場合はdockerを使う
% docker run --rm -it -v $(pwd):/app composer install --ignore-platform-reqs
--ignore-platform-reqsは必要ないかもしれない。プラットフォームの構成を無視してとにかくつっこむオプションである。ちなみに、これを行うとvendorの権限がrootになっちゃってて面倒って事があるかもしれないから、その場合はパーミッションを適切に直しておく事。
起動
起動する前にいくつか確認事項がある
% cp .env.example .env
しておく。
docker-composeを確認する
version: '3'
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
- mailpit
このように '${APP_PORT:-80}:80' に見られるように環境変数APP_PORTが設定されていればそちらを利用する事になっている。だから、たとえばport8000で起動したい場合は.envに以下のように追記する
そしたら
./vendor/bin/sail up
# あるいは
./vendor/bin/sail up -d
などして起動する。
artisanコマンドとkey:generate
% ./vendor/bin/sail artisan key:generate
INFO Application key set successfully.
このように実行する。つまり、artisanはsailの引数に渡す形で利用する事となる。
migrationの確認
laravelは最初からusersのmigrationがひっついてきている。
% find database
database
database/.gitignore
database/factories
database/factories/UserFactory.php
database/migrations
database/migrations/2019_08_19_000000_create_failed_jobs_table.php
database/migrations/2019_12_14_000001_create_personal_access_tokens_table.php
database/migrations/2014_10_12_100000_create_password_reset_tokens_table.php
database/migrations/2014_10_12_000000_create_users_table.php
database/seeders
database/seeders/DatabaseSeeder.php
従ってDBと通信できていれば即座にこれを投入できる。DBと通信できているかのテストも兼ねて実行してみよう。
% ./vendor/bin/sail artisan migrate
INFO Preparing database.
Creating migration table ............................................. 40ms DONE
INFO Running migrations.
2014_10_12_000000_create_users_table ................................. 79ms DONE
2014_10_12_100000_create_password_reset_tokens_table ................. 85ms DONE
2019_08_19_000000_create_failed_jobs_table ........................... 54ms DONE
2019_12_14_000001_create_personal_access_tokens_table ................ 78ms DONE
なお、DB自体はdocker-composeがいいようにやってくれている
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'
- './vendor/laravel/sail/database/mysql/create-testing-database.sh:/docker-entrypoint-initdb.d/10-create-testing-database.sh'
networks:
- sail
テスト用のDBもある
httpから確認する
APP_PORTを設定した場合はそのポートを見る http://localhost:8000 とか。
mailpitも入れた場合はデフォで8025番もlistenしているから http://localhost:8025 なども確認しておく事。
laravel breezeを使う場合
laravel breezeとは要するに面倒なユーザー登録やregistration、remember meなどなど認証スターターキットみたいなもんである。
これは以下のようにインストールする
% ./vendor/bin/sail composer require laravel/breeze --dev
bladeを使う場合
% ./vendor/bin/sail artisan breeze:install blade
を実行する。
そうすると以下のようなテイストのlogin画面などを作ってくれる
<div class="flex items-center justify-end mt-4">
@if (Route::has('password.request'))
<a class="underline text-sm text-gray-600 hover:text-gray-900 rounded-md focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500" href="{{ route('password.request') }}">
{{ __('Forgot your password?') }}
</a>
@endif
<x-primary-button class="ml-3">
{{ __('Log in') }}
</x-primary-button>
</div>
つまり、tailwind cssである。bootstrap5を使いたい場合はlaravel breezeではなく後述のlaravel uiがまだ使える。
react (+Inertia)とかを使う場合
予想通りとは思うが以下のようにする
% ./vendor/bin/sail artisan breeze:install react
laravel ui(要するにbootstrap5)を使いたい場合
% ./vendor/bin/sail composer require laravel/ui
./composer.json has been updated
Running composer update laravel/ui
Loading composer repositories with package information
Updating dependencies
Nothing to modify in lock file
Installing dependencies from lock file (including require-dev)
Package operations: 1 install, 0 updates, 0 removals
- Downloading laravel/ui (v4.2.2)
まだまだ利用可能。
% ./vendor/bin/sail artisan ui bootstrap --auth
INFO Authentication scaffolding generated successfully.
INFO Bootstrap scaffolding installed successfully.
WARN Please run [npm install && npm run dev] to compile your fresh scaffolding.
などといってくるので、これはnpmを起動しないといけない
% ./vendor/bin/sail npm install
run devはviteをちゃんとセットアップしないといけないので
% ./vendor/bin/sail npm run build
しといた方がとりあえず動作確認にはよい。
vite.config.jsファイル
bladeでもinertiaでもhmr(ホットリロード)の設定は変わらなくて
server: {
hmr: { host },
},
をexportされている {} の中に書いておくだけ。
import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
import react from '@vitejs/plugin-react';
// const host = 'example.org';
const host = 'localhost';
export default defineConfig({
server: {
hmr: { host },
},
plugins: [
laravel({
input: 'resources/js/app.jsx',
refresh: true,
}),
react(),
],
});
的な