Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

@defenestrator defenestrator commented Aug 4, 2020

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

@tonioriol

This comment has been minimized.

Copy link
Owner Author

@tonioriol tonioriol commented Aug 4, 2020

That's cool! Glad it helped :)

@sebsobseb

This comment has been minimized.

Copy link

@sebsobseb sebsobseb commented Apr 19, 2021

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

@Nirys

This comment has been minimized.

Copy link

@Nirys Nirys commented Oct 14, 2021

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

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