Created
September 12, 2018 02:29
-
-
Save synsa/9a8418f2941a34a79a4eec8fcf498dbf to your computer and use it in GitHub Desktop.
Laravel 5 deployment via rsync.
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
#!/bin/bash | |
# Application Deployer | |
# @author: @IAmReliQ | |
# @link: https://gist.github.com/reliq/75dc97a713982150b18d1825a907be4f | |
# | |
# | |
# Input: | |
# $1 - Server to deploy to | |
# $2 - Remote user home | |
# $3 - Remote username | |
# $4 - Laravel root (example: laravel-main) | |
# server | |
_server=$1 | |
# home | |
_home=$2 | |
# user | |
_user=$3 | |
# laravel root | |
_laravel_root=$4 | |
# setup params for rsync | |
printf "vendor\npublic\n*sass-cache\nstorage/photoc-skim\nstorage/*cache\nrsyncex*\n.*\n*node_modules\nresources/assets\ngulpfile.js\npackage.json\nbower.json\nwebpack.config.js\n" > "rsyncex" | |
printf "index.php\nuploads\n.htaccess\n" > "rsyncex.public" | |
chmod 777 rsyncex* | |
# copy to remote server - app main | |
rsync -uvrzhe "ssh -o StrictHostKeyChecking=no" --exclude-from="rsyncex" . "${_user}@${_server}:${_home}/${_laravel_root}" | |
# copy to remote server - public folder | |
rsync -uvvrzhe "ssh -o StrictHostKeyChecking=no" --exclude-from="rsyncex.public" public/ "${_user}@${_server}:${_home}/public_html" | |
# update packages on production | |
ssh $_user@$_server <<EOF | |
cd "${_home}/${_laravel_root}" | |
chmod 775 * | |
mkdir "storage" -p | |
chmod 777 "storage" -R | |
rm vendor -R || echo "Composer vendor directory didn't exist or couldn't be removed... Hmm..??" | |
# flush bootstrap/cache | |
php artisan clear-compiled | |
# install composer dependencies | |
composer install --no-dev | |
# activate production config | |
mv production.env .env | |
# cache config | |
php artisan config:cache | |
# symlink public directory | |
unlink public || true | |
ln -s $_home/public_html/ public | |
# setup public directory | |
cd "${_home}/public_html" | |
mv production.index.php index.php | |
mv production.htaccess .htaccess | |
EOF | |
# fin |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment