Skip to content

Instantly share code, notes, and snippets.

@kuya-joe
Forked from BenSampo/deploy.sh
Last active July 22, 2023 23:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kuya-joe/fc383addc2a8ac9f1dd2e3e9837f068e to your computer and use it in GitHub Desktop.
Save kuya-joe/fc383addc2a8ac9f1dd2e3e9837f068e to your computer and use it in GitHub Desktop.
Laravel deploy script
# Change to the project directory
cd $FORGE_SITE_PATH
# Turn on maintenance mode
php artisan down || true
# Pull the latest changes from the git repository
# git reset --hard
# git clean -df
git pull origin $FORGE_SITE_BRANCH
# Install/update composer dependecies
composer install --no-interaction --prefer-dist --optimize-autoloader --no-dev
# Restart FPM
( flock -w 10 9 || exit 1
echo 'Restarting FPM...'; sudo -S service $FORGE_PHP_FPM reload ) 9>/tmp/fpmlock
# Run database migrations
# WARNING: Don't need this in prooduction! (create a migration script instead for changing columns)
# php artisan migrate --force
# Clear caches
php artisan cache:clear
# Clear expired password reset tokens
php artisan auth:clear-resets
# Clear and cache routes
php artisan route:cache
# Clear and cache config
php artisan config:cache
# Clear and cache views
php artisan view:cache
# Install node modules
# npm ci
# Build assets using Laravel Mix
# npm run production --silent
# Turn off maintenance mode
php artisan up
@kuya-joe
Copy link
Author

In general I don't trust the migrate command (which migrates everything) in production wherein I prefer to run each migration individually.

This is how you can do so:

php artisan migrate --path=/database/migrations/<migration file.php>

Or if you have a bunch of migrations - you can specify a new folder and copy paste the migrations there. Just put the path to the directory instead like so.

php artisan migrate --path=/database/migrations/<directory>/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment