KTV/更新後部署流程(建議步驟).ini

49 lines
1.6 KiB
INI
Raw Permalink Normal View History

2025-05-26 16:28:16 +08:00
✅ Laravel 更新後部署流程(建議步驟)
1. 拉取新版程式碼
git pull origin main
2. 安裝依賴套件
composer install --no-dev --optimize-autoloader
3. 執行資料庫 migration如有 schema 變更)
php artisan migrate
4. 清除並重新快取設定與路由
php artisan config:clear
php artisan config:cache
php artisan route:clear
php artisan route:cache
php artisan view:clear
php artisan view:cache
5. (首次部署或有新增命令時)建立或更新任務排程 Crontab
檢查是否已有下列 crontab 設定crontab -e
分鐘 小時 日 月 星期 指令
* * * * * cd /path/to/your/project && php artisan schedule:run >> /dev/null 2>&1
這樣 Laravel 才能自動執行你在 routes/console.php 中定義的排程任務。
6. (選擇性)部署完立即執行某些 Artisan 指令
例如你可能希望部署後立即重建一次機器狀態資料表,可以執行:
php artisan machine_statuses:clear
7. 權限與快取設定(根據伺服器環境)
確認 storage 和 bootstrap/cache 目錄權限正確:
chmod -R 775 storage bootstrap/cache
chown -R www-data:www-data storage bootstrap/cache
✅ 完整部署腳本範例(可寫成 deploy.sh
#!/bin/bash
cd /var/www/your-project
git pull origin main
composer install --no-dev --optimize-autoloader
php artisan migrate --force
php artisan config:cache
php artisan route:cache
php artisan view:cache
php artisan machine_statuses:clear
echo "✅ Laravel 專案已更新並執行完成。"