When building with Laravel, deploying changes from your local machine to your production server shouldnโt be a chore. In this post, Iโll show you how to automate Laravel deployments to a DigitalOcean VPS using GitHub Actions โ so that every push to GitHub updates your live app. Fast, clean, and fully hands-free.
โ
Why Use GitHub Actions for Deployment?
๐ Automated: Every push triggers a deployment.
๐ง Smart: Only deploys on specific branches.
๐ Secure: Uses SSH with no manual login.
๐ซ No third-party CI/CD platforms needed.
๐ง Prerequisites
Before diving in, ensure:
You have a Laravel project hosted on GitHub.
Your production server (DigitalOcean) is running Ubuntu, PHP, Composer, and Laravel dependencies.
SSH access to the server (weโll use this for GitHub Actions).
1๏ธโฃ Generate SSH Key for GitHub
From your local machine:
ssh-keygen -t ed25519 -C "github_actions_deploy"
When prompted for a filename, use:
/home/engineer/.ssh/solssa_github_ci
This creates:
solssa_github_ci โ Private key
solssa_github_ci.pub โ Public key
2๏ธโฃ Add the Public Key to Your Server
Upload the public key to your DigitalOcean server:
ssh-copy-id -i ~/.ssh/solssa_github_ci.pub root@159.89.41.188
Test the connection:
ssh -i ~/.ssh/solssa_github_ci root@159.89.41.188
You should log in without a password.
3๏ธโฃ Add Private Key to GitHub Secrets
On your GitHub repo (SolssaTemplate), go to:
Settings > Secrets and variables > Actions
Create these 3 secrets:
Name Value
DO_SSH_KEY Contents of solssa_github_ci
DO_HOST 159.89.41.188
DO_USER root
4๏ธโฃ Create the GitHub Actions Workflow
In your Laravel project, create:
.github/workflows/deploy.yml
Paste this:
yaml
Copy
Edit
name: Deploy to DigitalOcean
on:
push:
branches:
- main # or 'master'
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Deploy to DigitalOcean via SSH
uses: appleboy/ssh-action@v1.0.0
with:
host: ${{ secrets.DO_HOST }}
username: ${{ secrets.DO_USER }}
key: ${{ secrets.DO_SSH_KEY }}
script: |
cd /var/www/solssa
git pull origin main
composer install --no-dev --optimize-autoloader
php artisan migrate --force
php artisan config:cache
php artisan route:cache
php artisan view:cache
โ๏ธ Update /var/www/solssa to your actual Laravel app directory on the server.
5๏ธโฃ Trigger Your First Deploy
Push any change to your GitHub main branch:
git add .
git commit -m "Automated deploy test"
git push origin main
Then visit the Actions tab on your repo to watch the magic happen. ๐
โจ Conclusion
By setting up this simple GitHub Actions workflow, youโve turned deployment into a single push operation โ no FTP, no SSH copy-pasting, just clean DevOps right inside GitHub.
This setup is perfect for small to mid-size Laravel apps and gives you a solid foundation to scale with more advanced CI/CD in the future.
Top comments (0)