Created
January 8, 2022 18:58
-
-
Save rjp2525/6c4cfa5d824a5f365b9dd92fb0199951 to your computer and use it in GitHub Desktop.
Laravel Forge Deployment Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Switch to the project directory | |
cd $FORGE_SITE_PATH | |
# Enable maintenance mode while deploying | |
$FORGE_PHP artisan down --render="errors::503" --redirect="/" || true | |
# Pull in the configured Forge deployment branch from GitHub (usually "main") | |
git pull origin $FORGE_SITE_BRANCH | |
# Install the project (production does not require development dependencies) | |
# Explanation of arguments: | |
# -n (--no-interaction) Does not prompt for any interactive actions/questions | |
# -prefer-dist Installs packages from distributed version (vs from source) | |
# --no-scripts Skips the execution of scripts defined in composer.json | |
# -o (--optimize-autoloader) Converts PSR-0/4 autoloading to classmap to get a faster autoloader | |
# --no-dev Skips installation and autoloading of packages in 'require-dev' | |
# -q (--quiet) Hides the output of the installation command | |
$FORGE_COMPOSER install -n --prefer-dist --no-scripts -o --no-dev --quiet | |
# Restart the FPM server | |
( flock -w 10 9 || exit 1 | |
echo 'Restarting FPM...'; sudo -S service $FORGE_PHP_FPM reload ) 9>/tmp/fpmlock | |
# Clear the previously cached application routes, then generate a new cached version | |
$FORGE_PHP artisan route:clear | |
$FORGE_PHP artisan route:cache | |
# Clear the previously cached application configuration, then generate a new cached config | |
$FORGE_PHP artisan config:clear | |
$FORGE_PHP artisan config:cache | |
# Clear the previously cached compiled views, then generate new cached views | |
$FORGE_PHP artisan view:clear | |
$FORGE_PHP artisan view:cache | |
# Run the migrations | |
$FORGE_PHP artisan migrate --force | |
# Clear expired password reset tokens | |
php artisan auth:clear-resets | |
# Install NPM modules (see: https://blog.npmjs.org/post/171556855892/introducing-npm-ci-for-faster-more-reliable) | |
# The 'ci' bypasses package.json and installs from the package lockfile instead | |
npm ci | |
# Run the npm production script | |
npm run production | |
# Restart the queue | |
$FORGE_PHP artisan queue:restart | |
# Restart supervisor | |
sudo supervisorctl restart all | |
# Disable maintenance mode | |
$FORGE_PHP artisan up |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment