Skip to content

Instantly share code, notes, and snippets.

@chrisblackwell
Last active May 5, 2022 22:40
Show Gist options
  • Save chrisblackwell/6f966ddf250dca56682c to your computer and use it in GitHub Desktop.
Save chrisblackwell/6f966ddf250dca56682c to your computer and use it in GitHub Desktop.
Git Post receive hook for Laravel deployment
#!/bin/sh
WEBROOT=/srv/www/apps.legendboats.com
GIT_WORK_TREE=$WEBROOT git checkout -f
cd $WEBROOT
# Check if a composer.json file is present
if [ -f composer.json ]; then
# Install or update packages specified in the lock file
composer install
fi
# bring the application down for maintenance. avoid the artisan command
touch storage/meta/down
echo "Application is now down."
# remove compiled/cache files if they exist
rm -f bootstrap/compiled.php
rm -f app/storage/meta/services.json
# install packages, this also regenerates the autoloader
composer install --no-scripts --no-dev --no-interaction --prefer-dist
# display the environment
php artisan env
# run any outstanding migrations
php artisan migrate --force
# optimize autoloader and compile common classes
php artisan optimize --force
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment