Manual FTP uploads cause downtime and errors. A simple Git workflow gives you predictable releases, instant rollbacks, and traceability. Here’s how to implement it for PHP apps (Laravel, Symfony, plain PHP) and static sites.
Table of Contents
- Release flow overview
- Create a staging environment
- Atomic deploys with symlinks
- Safe database migrations
- CI/CD pipeline example
- Instant rollbacks
- Security & secrets handling
- FAQs
1) Release flow overview
| Stage | Action | Outcome |
|---|---|---|
| Commit | Push to main branch | CI builds artifacts |
| Staging | Auto‑deploy to staging site | QA & checks run |
| Production | Blue‑green switch / canary rollout | Zero‑downtime go‑live |
2) Create a staging environment
- Use a subdomain (e.g.,
staging.example.com) with basic auth - Mirror production config but with test API keys and sandbox payment gateways
- Seed anonymized data for realistic QA
3) Atomic deploys with symlinks
- Upload each build to a new
releases/2025‑09‑30‑123456folder - Run composer/npm builds in the release directory
- Switch
current → releases/…with one symlink update - Keep
shared/for persistentstorageand.env
4) Safe database migrations
- Put the app in maintenance mode for schema changes that lock tables
- Use backward‑compatible migration pairs (expand → code → contract)
- Back up before deploying; verify row counts and constraints
5) CI/CD pipeline example
# Pseudo‑pipeline
on: push
jobs:
build:
steps:
- checkout
- install PHP 8.3 + Composer
- composer install --no-dev --optimize-autoloader
- npm ci && npm run build
- archive artifacts
deploy_staging:
needs: build
steps:
- rsync artifacts to staging releases/
- run migrations (safe)
- switch symlink → current
- run smoke tests
deploy_production:
needs: deploy_staging
steps:
- rsync artifacts to production releases/
- warm caches; prime CDN
- blue‑green flip; monitor
6) Instant rollbacks
- Keep the last 5–10 release folders
- Re‑point
currentsymlink to the previous release - Restore DB snapshot if a migration failed
7) Security & secrets handling
- Store secrets in environment variables (
.envoutside web root) - Rotate keys regularly; restrict SSH access with keys only
- Enable read‑only file permissions for the
currentrelease
Ship confidently, anytime
Adopt Git deploys, staging, and atomic releases for fast, reliable iterations.
8) FAQs
Can I use this on shared plans?
Yes — use SSH with Git pulls or rsync deploys. Keep builds outside the web root and switch via symlink.
What about asset pipelines?
Compile on CI or staging. Upload only built assets to production to keep deploys small and fast.
How do I handle long DB migrations?
Break them into expand/contract steps and run during low‑traffic windows. Always have a snapshot for quick recovery.