
Set Up CI/CD Pipelines & Automate Laravel Deployments
Learn GitHub Actions and how to auto-deploy any applications to the server when code is updated and pushed. Includes full YAML example, SSH deployment, and test automation tips.
Rejown Ahmed
π‘ Why CI/CD Matters for Developers
In modern web development, speed and reliability matter more than ever. Whether youβre building APIs, frontend apps, or backend systems, continuous integration and deployment (CI/CD) ensure your code gets tested and deployed automatically whenever you push updates.
With GitHub Actions, you can build powerful pipelines directly from your GitHub repository β no external service needed. Itβs simple, flexible, free and integrates seamlessly with any stack (Laravel, Node.js, Vue, React, etc.).
βοΈ What is CI/CD?
CI (Continuous Integration) β automatically test and verify code when itβs pushed. CD (Continuous Deployment) β automatically deploy code to your server if all tests pass.
For example:
- You push code to the
devbranch. - GitHub Actions runs automated tests.
- If all tests succeed, the app is deployed to your development server via SSH.
π§© Example: Auto Deploy Laravel to DEV Server
Hereβs a ready-to-use GitHub Actions workflow that deploys your Laravel app whenever you push to the dev branch.
# .github/workflows/deploy.yml
name: Deploy to DEV Server
on:
push:
branches:
- dev
jobs:
laravel-tests:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
- name: Install dependencies
run: composer install --no-interaction --prefer-dist
- name: Run PHPUnit tests
run: php artisan test
- name: Deploy to server
if: success() # Only deploy if tests passed
uses: appleboy/ssh-action@v1.1.0
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
password: ${{ secrets.PASSWORD }}
script: "cd /var/www/api/html && ./script/production.sh"
π Pro Tip:
Keep your SSH credentials (host, username, password) safe by storing them as GitHub Secrets β Go to Settings β Secrets and variables β Actions β New repository secret.
π The production.sh Script
This Bash script handles your actual server-side deployment safely and efficiently.
#!/bin/bash
set -e
echo "Deployment started ..."
# Enter maintenance mode or return true
(php artisan down) || true
# Pull the latest version of the app
git fetch --all
git reset --hard HEAD
git clean -f -d
git pull origin production
rm composer.lock
composer install --no-dev --no-interaction --prefer-dist --optimize-autoloader
php artisan optimize:clear
php artisan clear-compiled
php artisan optimize
php artisan up
echo "Deployment finished!"
π§ How It Works (Step-by-Step)
- Push code to the
devbranch. - GitHub Actions runs tests using PHPUnit or any configured test suite.
- If tests succeed β the SSH deploy action runs.
- The
production.shscript executes on your server, pulling the latest code and clearing caches. - Your app is live β automatically!
π§ͺ Adding Post-Deployment API Testing (Optional)
After deployment, you can even run automated API tests with Postman or Newman CLI to ensure your endpoints are working properly.
Add a step after deployment:
- name: Run Postman API Tests
run: |
npm install -g newman
newman run tests/api-collection.json --environment tests/dev-env.json
This ensures your frontend or mobile clients always connect to working APIs.
π Benefits of Using GitHub Actions for CI/CD
- β Free for public repos and affordable for private ones.
- βοΈ Native GitHub integration β no external setup.
- π Works with any framework (Laravel, Node.js, React, etc.).
- π§ Easily extendable with test, lint, and build steps.
- π Deploy anywhere β VPS, AWS, DigitalOcean, or Firebase.
π Wrapping Up
Setting up CI/CD pipelines with GitHub Actions is one of the easiest ways to automate your development workflow. Once you configure it, every push triggers:
- automated tests,
- followed by secure SSH deployment,
- and optionally, API tests with Postman.
This means less manual work, faster releases, and higher confidence in every deploy.
βοΈ Final Thoughts (for SEO)
If youβre serious about becoming a modern web developer, mastering tools like GitHub Actions, Postman, and API testing pipelines will make you stand out. Automate your builds, test your APIs, and deploy confidently β all from GitHub.
Why Every Frontend Developer Should Master Postman
Frontend developers who master Postman build faster, bug-free UIs. Learn how API testing, environments, and documentation in Postman supercharge your frontend workflow.
How to Transition from Developer to Technical Leader: Thinking Beyond the Code
Discover how to become a leader with strategic thinking, anticipating edge cases, and making informed decisions can prevent technical debt and drive long-term success.