Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Laravel: Bash deploy
#!/bin/sh
# Grant privileges
# echo "YOUR_USER ALL=NOPASSWD: /usr/sbin/service php7.4-fpm reload" | sudo tee -a /etc/sudoers.d/php-fpm > /dev/null
# echo "YOUR_USER ALL=NOPASSWD: /usr/sbin/service nginx restart" | sudo tee -a /etc/sudoers.d/php-fpm > /dev/null
# echo "YOUR_USER ALL=NOPASSWD: /usr/sbin/service supervisor restart" | sudo tee -a /etc/sudoers.d/php-fpm > /dev/null
NAME=$(date +"%m-%d-%Y-%H-%M-%S")
FOLDER=releases/$NAME
BACKUP=backup/before_$NAME.sql
echo "Backup..."
mysqldump -u USER -pPASSWORD DATABASE > $BACKUP
mkdir ${FOLDER}
cd ${FOLDER}
echo "Git clone..."
git clone git@bitbucket.org:USER/PROJECT.git .
rm -rf storage
ln -s ../../storage storage
ln -s ../../.env .env
echo "Composer install..."
composer install
echo "Npm install..."
npm install
npm run production
echo "Artisan..."
php artisan storage:link
php artisan route:clear
php artisan cache:clear
php artisan migrate --force
php artisan queue:restart
read -p "Restart and deploy? y/n:" answer
if [ $answer = "y" ]; then
cd ../../
if [ -f current ]; then
rm current;
fi
ln -s ${FOLDER} current
sudo service php7.4-fpm reload
sudo service nginx restart
sudo service supervisor restart
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment