Last active
February 17, 2019 10:50
-
-
Save kresnasatya/a7b0a5ea6e4e24ae62b3f2583a621861 to your computer and use it in GitHub Desktop.
Bash deploy in laravel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
REPO='[email protected]:BaliPHP/phpbali-site.git'; #nama repo saya | |
RELEASE_DIR='/var/www/phpbali-site/releases'; # direktori aplikasi saya | |
APP_DIR='/var/www/phpbali-site/app'; # direktori aplikasi saya | |
RELEASE="release_`date +%Y%m%d%H%M%s`"; | |
# tempat saya menaruh .env production file | |
# Jika Anda tidak ingin mengikuti cara ini pastikan Anda hapus perintah | |
# yang ada komentar # Copy .env file | |
ENV_PRODUCTION='/home/deployer/env-laravel/phpbali-site/production/.env'; | |
ROOT_DIR='/var/www/phpbali-site'; | |
SHARED_DIR='/var/www/phpbali-site/shared'; | |
# Fetch Latest Code | |
echo "Fetch Latest Code start"; | |
[ -d $RELEASE_DIR ] || mkdir -p $RELEASE_DIR; | |
cd $RELEASE_DIR; | |
git clone -b master $REPO $RELEASE; | |
echo "Fetch Latest Code done"; | |
# Composer | |
echo "Composer start"; | |
cd $RELEASE_DIR/$RELEASE; | |
composer install --prefer-dist --no-scripts; | |
php artisan clear-compiled --env=production; | |
php artisan optimize --env=production; | |
echo "Composer done"; | |
# Update permissions | |
echo "Update permissions start"; | |
cd $RELEASE_DIR; | |
chgrp -R www-data $RELEASE; | |
chmod -R ug+rwx $RELEASE; | |
echo "Update permissions done"; | |
# Check if shared directory is not exist | |
echo "Shared dir start"; | |
if [ ! -d "$SHARED_DIR" ]; then | |
# Create shared directory | |
mkdir $ROOT_DIR/shared; | |
cd $ROOT_DIR/shared && (mkdir -p storage storage/app storage/app/public storage/framework storage/framework/cache storage/framework/sessions storage/framework/views storage/logs); | |
fi | |
echo "Shared dir done"; | |
# Copy .env file | |
echo "Copy .env start"; | |
cp $ENV_PRODUCTION $ROOT_DIR/shared; | |
echo "Copy .env done"; | |
## Env File | |
echo "Env file start"; | |
cd $RELEASE_DIR/$RELEASE; | |
ln -nfs ../../shared/.env .env; | |
chgrp -h www-data .env; | |
echo "Env file done"; | |
## Logs | |
echo "Logs start"; | |
rm -r $RELEASE_DIR/$RELEASE/storage; | |
cd $RELEASE_DIR/$RELEASE; | |
ln -nfs ../../shared/storage storage; | |
chgrp -h www-data storage; | |
echo "Logs done"; | |
## Update Current Site | |
echo "Update current site start"; | |
ln -nfs $RELEASE_DIR/$RELEASE $APP_DIR; | |
chgrp -h www-data $APP_DIR; | |
echo "Update current site done"; | |
## PHP | |
echo "PHP reload start"; | |
sudo service php7.2-fpm reload; | |
echo "PHP reload done"; | |
## Setup artisan key generate command | |
echo "Artisan start"; | |
cd $APP_DIR; | |
php artisan key:generate | |
# Clear conf | |
php artisan config:clear | |
php artisan config:cache | |
# Run migration | |
php artisan migrate --force | |
# Symlink storage folder with public folder | |
php artisan storage:link | |
echo "Artisan done"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment