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)