Bash Scripts for Laravel PHP Linux Devops
August 25, 2020
bash debian devops laravelHaving spent the summer learning more of the Devops toolkit, I often come back to bash shell scripts to achieve something.
importEnv.sh
I wanted a little script to import the values of the .env file to use in the bash scripts. This works as i expect.
#!/bin/bash
source /var/www/laravel/.env
echo $DB_USERNAME
mysqlBackup
This is a one liner to backup all the mysql databases.
mysql -u root -p -N -e 'show databases' | while read dbname; do mysqldump -u root -p --complete-insert --routines --triggers --single-transaction "$dbname" > "$dbname".sql; done
deploy.sh
Working with the jigsaw static site builder, i wrote this simple script to copy the production version of the site to another directory and deploy it to the github pages site.
#!/bin/bash -e
echo "Deploying build_production to allotmentandy.github.io"
echo "---------"
cd build_production
cp -r * /var/www/allotmentandy.github.io
cd /var/www/allotmentandy.github.io
git add .
git commit -m "update"
git push
echo 'finished'
clearLaravelCaches.sh
#!/bin/bash
echo "This a bash script to run composer clear the caches)"
echo "--------------"
php -v
#echo "--------------"
cd /var/www/laravel
php artisan down
composer dump-autoload -o
php artisan view:clear
php artisan config:clear
php artisan cache:clear
php artisan route:clear
php artisan clear-compiled
php artisan config:cache
php artisan optimize
php artisan up
If you would like to contact me with this form on londinium.com, ilminster.net or via Twitter @andylondon