Laravel Forge-like deployment script
When you're working on Laravel projects, you might not always have Forge ready to use. Here's an easy script that does what Forge does for deploying on Ubuntu servers. You can run it yourself or set it up to deploy automatically however you like.
#!/bin/bashset -eecho $(date)if [ ! -f /tmp/fpmlock ]thentouch /tmp/fpmlockchmod 666 /tmp/fpmlockfiPROJECT_COMPOSER='php /usr/local/bin/composer'PROJECT_PHP='php'PROJECT_PHP_FPM='php8.3-fpm'PROJECT_SITE_BRANCH='main'PROJECT_SITE_PATH='/var/www/html'PROJECT_SITE_USER='www-data'cd $PROJECT_SITE_PATHgit pull origin $PROJECT_SITE_BRANCH$PROJECT_COMPOSER install --no-dev --no-interaction --prefer-dist --optimize-autoloader( flock -w 10 9 || exit 1echo 'Restarting FPM...'; sudo -S service $PROJECT_PHP_FPM reload ) 9>/tmp/fpmlockif [ -f artisan ]; then$PROJECT_PHP artisan migrate --forcefi$PROJECT_PHP artisan cache:clear$PROJECT_PHP artisan view:clear$PROJECT_PHP artisan config:cache$PROJECT_PHP artisan view:cache
#!/bin/bashset -eecho $(date)if [ ! -f /tmp/fpmlock ]thentouch /tmp/fpmlockchmod 666 /tmp/fpmlockfiPROJECT_COMPOSER='php /usr/local/bin/composer'PROJECT_PHP='php'PROJECT_PHP_FPM='php8.3-fpm'PROJECT_SITE_BRANCH='main'PROJECT_SITE_PATH='/var/www/html'PROJECT_SITE_USER='www-data'cd $PROJECT_SITE_PATHgit pull origin $PROJECT_SITE_BRANCH$PROJECT_COMPOSER install --no-dev --no-interaction --prefer-dist --optimize-autoloader( flock -w 10 9 || exit 1echo 'Restarting FPM...'; sudo -S service $PROJECT_PHP_FPM reload ) 9>/tmp/fpmlockif [ -f artisan ]; then$PROJECT_PHP artisan migrate --forcefi$PROJECT_PHP artisan cache:clear$PROJECT_PHP artisan view:clear$PROJECT_PHP artisan config:cache$PROJECT_PHP artisan view:cache