🚀 Effortless Web App Deployments: Mastering GitHub Actions with DigitalOcean

I’m Insaf Nilam, a full-stack developer passionate about crafting clean, efficient, and future-ready software. I love solving complex problems, exploring new tech stacks, and sharing my learnings through blogs. When I’m not coding, I’m probably tweaking deployments, experimenting with microservices, or geeking out over cloud architecture.
Manually deploying applications can be exhausting:
SSH into the server
Pull the latest code (or upload zip files 🤦)
Run Composer, NPM, and Artisan commands
Fix file permissions and run migrations
Pray nothing breaks
But what if all of this could be automated?
That’s where CI/CD with GitHub Actions comes in.
🔑 Prerequisites
Before diving in, make sure you’ve covered the basics:
Fortify Your DigitalOcean Droplet: A Step-by-Step Security Guide for Ubuntu 24.04
Fortify Your Droplet: Unlock Free HTTPS with Let’s Encrypt SSL
Streamlined App Deployment on Ubuntu 24.04 with DigitalOcean
These guides walk you through preparing your droplet and setting up your stack. Once ready, we can add automation on top.
1️⃣ Traditional Deployment (Why It’s Painful)
Normally, you’d log in and run something like:
ssh deploy_user
cd /var/www/html/<app>
git pull origin main
composer install --optimize-autoloader
npm install && npm run build
If your server has limited resources, installing Composer + NPM dependencies there can choke the machine. You also end up juggling SSH keys, restarting agents (eval "$(ssh-agent -s)"), and repeating the same steps over and over.
👉 Automation saves your sanity.
2️⃣ CI/CD with GitHub Actions
Instead of building on the server, we offload builds to GitHub Actions. Every time you push code:
main→ Deploys to Production Environment
Here’s an example GitHub workflow (deploy.yml):
name: Deploy Application to Production Server
on:
push:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v5
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.4
- name: Install Composer Dependencies
run: composer install --optimize-autoloader --no-dev --no-progress --no-interaction --prefer-dist
- name: Setup Node.js
uses: actions/setup-node@v5
with:
node-version: '22'
- name: Install NPM Dependencies
run: npm install
- name: Build Assets
run: npm run build
- name: Deploy Files to Server
uses: easingthemes/ssh-deploy@v5.1.0
env:
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
SOURCE: "."
REMOTE_HOST: ${{ secrets.VPS_HOST }}
REMOTE_USER: ${{ secrets.VPS_USER }}
TARGET: "/var/www/html/<app>"
- name: Run Remote Artisan Commands
uses: appleboy/ssh-action@v1.2.2
with:
host: ${{ secrets.VPS_HOST }}
username: ${{ secrets.VPS_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
cd /var/www/html/<app>
php artisan migrate --force
php artisan optimize
3️⃣ Setting Up GitHub Secrets
Go to Repo → Settings → Secrets & variables → Actions and add:
VPS_HOST= your server IPVPS_USER= deploy userSSH_PRIVATE_KEY= your private RSA key
⚠️ Note: In our previous guide, we generated ECDSA keys. These don’t work with some GitHub Actions. Instead, generate an RSA key:
cd ~/.ssh
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
ssh-copy-id <username>@<public_ip_address>
4️⃣ How It All Comes Together
✅ Push code → GitHub Actions runs builds → Files sync to server → Migrations + cache run → Site live.
No more manual SSH to the server
No more broken deployments
No more wasted server resources
✨ Final Thoughts
CI/CD may look intimidating at first, but once set up, it:
Saves hours of repetitive work
Reduces human errors
Keeps environments consistent
Offloads heavy builds to GitHub, not your VPS
Your DigitalOcean droplet stays lean and fast, while your deployments stay reliable and stress-free.
👉 Pair this with Streamlined App Deployment on Ubuntu 24.04 to guide readers from manual setup → automated CI/CD pipeline.




