Skip to content

Instantly share code, notes, and snippets.

@stancl
Last active December 10, 2024 10:58
Show Gist options
  • Save stancl/cab04a411f136047e80c1de81528eb23 to your computer and use it in GitHub Desktop.
Save stancl/cab04a411f136047e80c1de81528eb23 to your computer and use it in GitHub Desktop.
Deploy using GitHub actions and SSH to a VPS
#!/bin/sh
set -e
vendor/bin/phpunit
npm run prod
git add .
(git commit -m "Build frontend assets for deployment to production") || true
(git push) || true
git checkout production
git merge master
git push origin production
git checkout master
name: CD
on:
push:
branches: [ production ]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Deploy to <your domain>
uses: appleboy/ssh-action@master
with:
username: <your username>
host: <your domain>
password: ${{ secrets.SSH_PASSWORD }}
script: 'cd /var/www/html && ./server_deploy.sh'
#!/bin/bash
set -e
echo "Deploying application ..."
# Enter maintanance mode
php artisan down
# Update codebase
git pull origin production
# Install dependencies based on lock file
composer install --no-interaction --prefer-dist --optimize-autoloader
# Migrate database
php artisan migrate --force
# Clear cache
php artisan optimize
# Reload PHP to update opcache
echo "" | sudo -S service php7.4-fpm reload
# Exit maintenance mode
php artisan up
echo "🚀 Application deployed!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment