Skip to content

Instantly share code, notes, and snippets.

@philipborbon
Last active January 22, 2023 09:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save philipborbon/5b3cec6ff825071f50b0f80a8f395c30 to your computer and use it in GitHub Desktop.
Save philipborbon/5b3cec6ff825071f50b0f80a8f395c30 to your computer and use it in GitHub Desktop.
Deploy code to `public_html`
#!/bin/bash
TARGET="/home/wtqeysrg/project"
GIT_DIR="/home/wtqeysrg/project.git"
PUBLIC_DIR="/home/wtqeysrg/public_html"
BRANCH="master"
while read oldrev newrev ref
do
# only checking out the master (or whatever branch you would like to deploy)
if [ "$ref" = "refs/heads/$BRANCH" ];
then
echo "Ref $ref received. Deploying ${BRANCH} branch to production..."
git --work-tree=$TARGET --git-dir=$GIT_DIR checkout -f $BRANCH
cp -a $TARGET/public/. $PUBLIC_DIR
sed -i "s/__DIR__\.'\/\.\.\//__DIR__\.'\/\.\.\/project\//g" $PUBLIC_DIR/index.php
php composer install --optimize-autoloader --no-dev --working-dir=$TARGET
php $TARGET/artisan config:cache
php $TARGET/artisan route:cache
php $TARGET/artisan view:cache
php $TARGET/artisan queue:restart
else
echo "Ref $ref received. Doing nothing: only the ${BRANCH} branch may be deployed on this server."
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment