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?

本番環境(エックスサーバー)で Laravel プロジェクトを更新する手順

Posted at

本番環境(エックスサーバー)で Laravel の コード更新・ストレージフォルダ作成・Fakerの修正・データベースリセット までの 完全な手順 です。

1. SSH で本番環境にログイン

ローカルPCから本番環境(エックスサーバー)に SSH 接続:

ssh -i パスフレーズ.key サーバーID@サーバー番号.xserver.jp -p 10022

プロジェクトのディレクトリに移動:

cd /home/akkun1114/akkun1114.com/public_html/exp-alert.akkun1114.com/EXP-alert

今回はサブドメインでやっているためこのルート

2. 最新のコードをアップロード

リモートリポジトリから最新のコードを取得:

git pull origin main

3. storage/app/public/items フォルダを作成

ストレージフォルダ items がない場合は作成:

mkdir -p storage/app/public/items
chmod -R 775 storage bootstrap/cache

✅ -p オプションで親フォルダがない場合も自動作成!
✅ 書き込み権限を適切に設定!

4. シンボリックリンクを再生成

rm -rf public/storage
php artisan storage:link

✅ public/storage/items/ から正しく参照できるようにする!

5. Faker

Faker を使用する場合、再インストール:

composer require fakerphp/faker --dev
composer dump-autoload

✅ オートロードを更新して、Faker クラスが正しく認識されるようにする!

6. 依存関係の更新

composer install --no-dev --optimize-autoloader

✅ --no-dev で本番環境に不要な開発用パッケージをインストールしない!

7. データベースをリセット & シーディング

⚠️ migrate:fresh は全データを削除するので慎重に!

php artisan migrate:fresh --seed

✅ データベースをリセットし、Seeder で初期データを投入!

8. キャッシュをクリア

php artisan config:clear
php artisan cache:clear
php artisan route:clear
php artisan view:clear

✅ キャッシュが古いままだと変更が反映されないことがある!

9. 本番環境で動作確認

ブラウザで、変更が反映されているか確認。

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?