Laravel Mastery: Deployment & DevOps

11 minute read Laravel Mastery · Part 8

Streamline your Laravel deployment process with strategies for CI/CD pipelines, zero-downtime deploys, environment configuration, and DevOps tooling.

A polished Laravel app deserves a polished deployment pipeline. Whether you’re solo or scaling, DevOps practices help you deploy faster, safer, and with confidence.

Environments & Configuration

Use .env for sensitive and dynamic config. Never commit .env to Git. Define environment-specific .env.production and .env.staging files.

In config/*.php, use:

'api_key' => env('API_KEY'),

Cache configs for performance:

php artisan config:cache

Zero-Downtime Deployment

Use Laravel Envoyer or a custom script for atomic deploys.

Alternative: manual symlink strategy:

/releases/current -> /releases/20250626_123456

Use php artisan down with --secret for access:

php artisan down --secret="super-secret-code"

Then deploy, then:

php artisan up

Deploy with Laravel Forge

  • Provision server
  • Connect repo (GitHub/Bitbucket)
  • Configure deployments
  • Add environment variables
  • Queue monitoring with Horizon

Custom Deployment with Envoy

composer require laravel/envoy --dev

Create Envoy.blade.php:

@servers(['prod' => 'user@yourserver'])

@task('deploy', ['on' => 'prod'])
    cd /var/www/app
    git pull origin main
    composer install --no-dev
    php artisan migrate --force
    php artisan config:cache
    php artisan queue:restart
@endtask

Run:

vendor/bin/envoy run deploy

CI/CD Pipelines

Use GitHub Actions / GitLab CI / Bitbucket Pipelines:

Example .github/workflows/deploy.yml:

name: Deploy Laravel

on:
  push:
    branches: [ main ]

jobs:
  deploy:
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v4
    - name: Setup PHP
      uses: shivammathur/setup-php@v2
      with:
        php-version: '8.3'
    - run: composer install --no-dev --optimize-autoloader
    - run: php artisan config:cache
    - run: php artisan route:cache
    - run: curl -X POST https://forge.laravel.com/servers/.../deploy

Health Checks & Rollbacks

  • Use /health route for uptime monitors (e.g. Oh Dear, Pingdom)
  • Keep previous releases ready for rollback
  • Use Supervisor to auto-restart failed queue workers

Real-World Application

In the jewellery ecommerce project, we:

  • Used Forge + Horizon
  • Deployed via GitHub Actions
  • Achieved <10s rollback time
  • Added deployment Slack notifications via Webhooks

Best Practices

  • Automate what’s repeatable
  • Use queues and horizon monitoring
  • Document .env variable expectations
  • Use php artisan config:cache, route:cache, view:cache
  • Validate deploys with post-deploy health check