1
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?

Laravel本番環境構築における実行ユーザーの整理

Posted at

✅ 目的ごとの実行ユーザー判断

処理内容 実行ユーザー 理由・補足
Apacheの起動/停止/インストール root サービス制御は root 権限が必要
firewall の設定 root ネットワーク制御は root 権限が必要
PHP / Git / Composer / Node.js のインストール root システム全体に影響するため root で実行
MariaDBのインストールや初期設定(mysql_secure_installation) root DBサーバーの設定は root 必須
Laravelアプリの clone(git clone) root or apache どちらでも良いが、Apacheが読めるようにすること(後でchownでも可)
composer install root Laravel実行はApacheなので読めればOK(後でパーミッション調整)
npm install, npm run build(Tailwindなど) root Apacheが直接実行しないので root でOK(PDF生成しない場合)
Browsershot を使う場合の npm install apache Laravel内からNodeを呼び出すため、Apacheが必要なキャッシュを作る必要あり
Browsershot に必要な ~/.cache 作成 apache HOMEディレクトリ(例:/var/www/.cache)を Apache 所有に
PDF/印刷機能の .env 設定 - Apacheで動作するようにBROWSERSHOT_HOME=/var/www等を指定する
Laravel Artisanコマンド(key:generate 等) root or apache 基本 root で問題ない(Apacheでキャッシュ書き込みできる前提)
storage や cache のパーミッション設定 root chown -R apache:apachechmod -R 775 など

✅ Browsershot(PDF生成)を使うときの注意

項目 対応内容
Puppeteerのnpm install sudo -u apache npm installで実行
HOMEディレクトリ /var/www.cache 作って apache:apache に所有権を渡す
.env設定 BROWSERSHOT_HOME=/var/www を追加
config/browsershot.php putenv('HOME=' . env('BROWSERSHOT_HOME', '/var/www')); を記載

✅ 判断のポイントまとめ

判定基準 実行ユーザー
サーバーやパッケージをインストール・設定する root
Laravelの処理をApache経由で実行する必要がある apache
一時的な初期構築コマンドでApacheは関与しない root
1
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
1
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?