Skip to content

Instantly share code, notes, and snippets.

@rdp77
Last active May 14, 2025 08:57
Show Gist options
  • Save rdp77/408aa8de8b838ce40fd8e87ea95c0e5a to your computer and use it in GitHub Desktop.
Save rdp77/408aa8de8b838ce40fd8e87ea95c0e5a to your computer and use it in GitHub Desktop.
Laravel Deployment Github Actions
name: Deploy Laravel App to Production Server
on:
push:
branches:
- main # Trigger deployment only when pushing to the main branch
jobs:
deploy:
runs-on: ubuntu-latest
steps:
# Step 1: Checkout the repository code
- name: Checkout code
uses: actions/checkout@v3
# Step 2: Start the SSH agent and load the private key from secrets
- name: Setup SSH access
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.DEPLOY_KEY }}
# Step 3: Connect to the server and run deployment commands
- name: SSH into server and deploy
run: |
ssh -o StrictHostKeyChecking=no ${{ secrets.SERVER_USER }}@${{ secrets.SERVER_HOST }} << 'EOF'
# Navigate to the Laravel project directory
cd /www/wwwroot/website
# Fetch and hard reset to match the remote main branch
git fetch origin
git reset --hard origin/main
# Install only production dependencies
composer install --no-dev --optimize-autoloader
# Clear and cache the Laravel configuration
php artisan config:clear
php artisan config:cache
# Create symbolic link for storage (public storage directory)
php artisan storage:link
# Run database migrations (forced)
php artisan migrate --force
# Set correct file ownership for web server access
chown -R www:www . 2>/dev/null
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment