CI/CD with GitHub Actions
Test and deploy PHP automatically on every push.
CI/CD for PHP
Every push should be tested, linted, statically analyzed, and — when green on the main branch — built into an image and deployed. GitHub Actions runs this pipeline on managed runners triggered by repo events.
We'll build a workflow that runs PHPUnit on a real MySQL service, caches Composer, runs PHPStan, builds a Docker image, and deploys.
Workflow Anatomy
A workflow lives in .github/workflows/*.yml. It has on: triggers, one or more jobs:, and each job has steps:. Jobs run on isolated runners in parallel unless linked by needs:.
name: CI
on:
push:
branches: [main]
pull_request:
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4All lessons in this course
- Containerizing a PHP Application
- Multi-Stage Builds and Optimization
- Docker Compose for Local Stacks
- CI/CD with GitHub Actions