Skip to content

Instantly share code, notes, and snippets.

@uluumbch
Created March 26, 2026 02:22
Show Gist options
  • Select an option

  • Save uluumbch/d056d2d8975488aab5de1d173a2a127f to your computer and use it in GitHub Desktop.

Select an option

Save uluumbch/d056d2d8975488aab5de1d173a2a127f to your computer and use it in GitHub Desktop.
auto deploy laravel project to hosting using ssh CI/CD
name: deploy
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
environment: Production
steps:
- name: Deploy to Production via SSH
uses: appleboy/ssh-action@v1
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
password: ${{ secrets.SSH_PASSWORD }}
port: ${{ secrets.SSH_PORT }}
script: |
# Navigate to the project folder
cd ${{ secrets.PROJECT_PATH }}
# Put app in maintenance mode
php artisan down --retry=60
# Pull the latest changes from main branch
git pull origin main
# Install/Update Composer dependencies
composer install --no-interaction --prefer-dist --optimize-autoloader --no-dev
# Install/Update Node dependencies and build assets
npm ci
npm run build
# Run database migrations
php artisan migrate --force
# Clear all caches
php artisan optimize:clear
# Cache configs, routes, and views for performance
php artisan config:cache
php artisan route:cache
php artisan view:cache
php artisan event:cache
# Bring the application back online
php artisan up
echo "✅ Deployment completed successfully!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment