Skip to content

Instantly share code, notes, and snippets.

@triswan
Last active September 8, 2020 08:07
Show Gist options
  • Save triswan/cfa9ebe1afc926223866f0bed1c11363 to your computer and use it in GitHub Desktop.
Save triswan/cfa9ebe1afc926223866f0bed1c11363 to your computer and use it in GitHub Desktop.
Laravel Deployment
#!/bin/sh
#
## store the arguments given to the script
read oldrev newrev refname
## Where to store the log information about the updates
LOGFILE=./post-receive.log
# The deployed directory (the running site)
DEPLOYDIR=/home/swamedia/source/portal-elogistics
## Record the fact that the push has been received
echo -e "Received Push Request at $( date +%F )" >> $LOGFILE
echo " - Old SHA: $oldrev New SHA: $newrev Branch Name: $refname" >> $LOGFILE
## Update the deployed copy
echo "Starting Deployment" >> $LOGFILE
echo " - Starting code update"
GIT_WORK_TREE="$DEPLOYDIR" git checkout -f
echo " - Finished code update"
echo " - Starting dependencies install & build"
cd "$DEPLOYDIR"
/home/swamedia/opt/bin/composer install --no-ansi --no-interaction --no-progress --no-scripts --optimize-autoloader
/home/swamedia/opt/node-v6.11.4-linux-x64/bin/npm run dev
cd -
echo " - Finished dependencies install & build"
echo " - Starting laravel optimization"
cd "$DEPLOYDIR"
#php artisan clear-compiled
php artisan cache:clear
php artisan view:clear
php artisan config:cache
php artisan route:cache
php artisan optimize
php artisan migrate
cd -
echo " - Finished laravel optimization"
echo "Finished Deployment" >> $LOGFILE
# Install application dependencies, such as the Laravel framework itself.
#
# If you run composer update in development and commit the `composer.lock`
# file to your repository, then `composer install` will install the exact
# same versions in production.
composer install --no-interaction
# npm run prod
php artisan clear:view
php artisan route:cache
php artisan config:cache
php artisan storage:link
# Clear the old boostrap/cache/compiled.php
php artisan clear-compiled
# Recreate boostrap/cache/compiled.php
php artisan optimize
# Migrate any database changes
php artisan migrate
git reset --hard
git pull origin develop
composer install
cp .env.example .env
php artisan key:generate
php artisan migrate --seed
php artisan cache:clear
php artisan config:clear
php artisan storage:link
sudo chown -R erp:www-data /var/www/app/amlo2/
find /var/www/app/amlo2/ -type f -exec chmod 664 {} \;
find /var/www/app/amlo2/ -type d -exec chmod 775 {} \;
chgrp -R www-data storage bootstrap/cache
chmod -R ug+rwx storage bootstrap/cache
#First time
git clone <repo url>
cd <repo dir>
sudo chown -R user:www-data .
sudo chmod 775 -R storage/
sudo chmod 775 -R bootstrap/cache
cp .env.example .env
vim .env
composer install
php artisan storage:link
php artisan migrate --seed
php artisan optimize
#Update
#sh pg_backup.sh
#download backup
php artisan down --message="Sedang ada pemeliharaan, silakan kembali lagi nanti..."
php artisan optimize:clear
git pull origin master
composer dump
composer install --no-interaction
php artisan migrate
#php artisan db:seed --class=BatchEtollTableSeeder #OR
#php artisan migrate:fresh --seed
php artisan optimize
php artisan up
#If there's a problem with permission cache
sudo chown -R user:www-data .
sudo chmod 775 -R storage/
sudo chmod 775 -R bootstrap/cache
#Manual clear cache
sudo php artisan cache:forget spatie.role.cache
sudo php artisan cache:forget spatie.permission.cache
sudo php artisan cache:clear
rsync -avz app/Repositories/ swaarief@192.168.5.41://home/swaarief/source/portal-elogistics/app/Repositories/
rsync -avz resources/ swaarief@192.168.5.41://home/swaarief/source/portal-elogistics/resources/
rsync -avz app/ swaarief@192.168.5.42://home/swaarief/source/portal-elogistics/app/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment