デプロイメント
Laravelデプロイメント
Section titled “Laravelデプロイメント”本番環境の設定
Section titled “本番環境の設定”# 環境変数の設定# .envファイルを編集APP_ENV=productionAPP_DEBUG=falseAPP_URL=https://example.com
# アプリケーションキーの生成php artisan key:generate
# キャッシュの最適化php artisan config:cachephp artisan route:cachephp artisan view:cacheサーバー設定
Section titled “サーバー設定”# Nginx設定例server { listen 80; server_name example.com; root /var/www/my-app/public;
add_header X-Frame-Options "SAMEORIGIN"; add_header X-Content-Type-Options "nosniff";
index index.php;
charset utf-8;
location / { try_files $uri $uri/ /index.php?$query_string; }
location = /favicon.ico { access_log off; log_not_found off; } location = /robots.txt { access_log off; log_not_found off; }
error_page 404 /index.php;
location ~ \.php$ { fastcgi_pass unix:/var/run/php/php8.1-fpm.sock; fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; include fastcgi_params; }
location ~ /\.(?!well-known).* { deny all; }}デプロイスクリプト
Section titled “デプロイスクリプト”#!/bin/bash# コードの取得git pull origin main
# 依存関係のインストールcomposer install --no-dev --optimize-autoloader
# マイグレーションphp artisan migrate --force
# キャッシュのクリアと再生成php artisan config:cachephp artisan route:cachephp artisan view:cache
# 権限の設定chmod -R 755 storage bootstrap/cachechown -R www-data:www-data storage bootstrap/cache