Skip to content

Instantly share code, notes, and snippets.

@tonioriol
Forked from rap2hpoutre/laravel-forge-deploy.sh
Last active April 25, 2023 22:20
Show Gist options
  • Star 20 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save tonioriol/e2f7d159e8905d69d2a9bd042f7b1778 to your computer and use it in GitHub Desktop.
Save tonioriol/e2f7d159e8905d69d2a9bd042f7b1778 to your computer and use it in GitHub Desktop.
Laravel Forge zero downtime deployment script
# stop script on error signal
set -e
SITE="your-site-original-folder-name.com"
DEPL="/home/forge/deployments/${SITE}"
# create directory and any intermediate directories if don't exist
mkdir -p ${DEPL}
CUR="/home/forge/${SITE}"
NEW="${DEPL}/new"
BKP="${DEPL}/backup"
# remove old deployment folders
if [ -d ${NEW} ]; then
rm -R ${NEW}
fi
if [ -d ${BKP} ]; then
rm -R ${BKP}
fi
cp -R ${CUR} ${NEW}
cd ${NEW}
# REGULAR SCRIPT (git pull, whatever you do to build assets, reload php clean opcache...)
git pull origin develop
composer install --no-interaction --prefer-dist --optimize-autoloader --no-dev
echo "" | sudo -S service php7.1-fpm reload
# /REUGLAR SCRIPT
# Switch (downtime for microseconds)
mv ${CUR} ${BKP}
mv ${NEW} ${CUR}
@defenestrator
Copy link

Thanks for this, if I make improvements to it I will link a gist here. Handy.

@tonioriol
Copy link
Author

That's cool! Glad it helped :)

@sebsobseb
Copy link

Thanks for this!
Btw; small typo in # /REUGLAR SCRIPT -> # /REGULAR SCRIPT

@Nirys
Copy link

Nirys commented Oct 14, 2021

Legend mate thank you. Just saved me a few hours!

@zacksmash
Copy link

I would make this one change on the $SITE variable

SITE=${FORGE_SITE_PATH#"/home/forge/"}

That way, it's fully dynamic and you could copy/paste to a testing/prod environment without changing much.

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