Does Laravel Work With GitHub Actions?
Laravel and GitHub Actions work seamlessly together; Actions is a first-class CI/CD choice for Laravel projects with excellent native support.
Quick Facts
How Laravel Works With GitHub Actions
Laravel integrates excellently with GitHub Actions because Actions provides a flexible, container-based CI/CD environment that handles PHP, Composer, and common Laravel tooling natively. You define workflows in YAML files (.github/workflows/) that trigger on pushes, pull requests, or schedules. A typical Laravel workflow installs dependencies via Composer, runs PHPUnit tests, executes Psalm for static analysis, and optionally deploys to production. The experience is streamlined: GitHub Actions has built-in Composer caching, matrix testing across PHP versions, and service containers (MySQL, Redis) with zero configuration. Most Laravel projects use a single workflow file that covers testing and optionally building/deploying. The main architectural consideration is that Actions runs in ephemeral containers, so persistent state requires external services or artifacts. Laravel's testing infrastructure (Pest, PHPUnit) and tooling ecosystem (Laravel Dusk for browser testing, Livewire testing) all work perfectly. Many Laravel projects also use GitHub Actions for database migrations, queue job testing, and scheduled tasks validation.
Best Use Cases
Laravel Test & Deploy Workflow
No installation needed; add file to .github/workflows/ci.ymlname: Laravel CI
on:
push:
branches: [main, develop]
pull_request:
branches: [main]
jobs:
test:
runs-on: ubuntu-latest
services:
mysql:
image: mysql:8.0
env:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: laravel_test
options: >-
--health-cmd="mysqladmin ping -h 127.0.0.1"
--health-interval=10s
--health-timeout=5s
--health-retries=3
ports:
- 3306:3306
steps:
- uses: actions/checkout@v3
- uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
extensions: mysql, redis
tools: composer
- name: Install dependencies
run: composer install --no-interaction --prefer-dist
- name: Setup environment
run: cp .env.example .env.testing && php artisan key:generate --env=testing
- name: Run tests
run: php artisan test
env:
DB_HOST: 127.0.0.1
DB_DATABASE: laravel_test
DB_USERNAME: root
DB_PASSWORD: rootKnown Issues & Gotchas
Database transactions don't persist between workflow steps unless using real database services
Fix: Use GitHub Actions service containers (MySQL/PostgreSQL) or configure SQLite in-memory for testing. Set DB_HOST to localhost and expose ports.
PHP extensions may not be pre-installed in the default ubuntu-latest runner
Fix: Use shivammathur/setup-php action to install extensions (redis, pgsql, etc.) matching your Laravel requirements.
Composer dependencies cache can grow stale or cause version conflicts in workflows
Fix: GitHub Actions caches Composer automatically, but add explicit cache invalidation keys if changing PHP versions or dependencies.
Environment variables (.env) aren't automatically available in workflow steps
Fix: Use GitHub Secrets for sensitive values and create .env.testing explicitly in workflow before running tests.
Alternatives
- •GitLab CI/CD with .gitlab-ci.yml for similar workflow-as-code experience with tighter integration on GitLab repositories
- •Jenkins with Freestyle or Pipeline jobs for self-hosted CI/CD with more control but higher operational overhead
- •Laravel Vapor with automatic GitHub deployments for serverless Laravel hosting with integrated CI/CD
Resources
Related Compatibility Guides
Explore more compatibility guides