PHP Deployment on Cloud Platforms
Also Known As
PHP on AWS
PHP serverless
Bref
ECS PHP
TL;DR
Deployment options for PHP on AWS, GCP, and Azure — EC2/VMs, containers (ECS, Cloud Run), serverless (Lambda via Bref), and PaaS (Elastic Beanstalk, App Engine).
Explanation
PHP cloud deployment options: EC2/VMs (full control, nginx + PHP-FPM, manual scaling), ECS/Fargate (containerised PHP-FPM, auto-scaling, no server management), Cloud Run/GCP (container on demand, scales to zero), Lambda + Bref (serverless PHP, pay per invocation, cold starts), Elastic Beanstalk/App Engine (PaaS, abstracts infrastructure). For most PHP web apps: ECS Fargate or Cloud Run offer the best balance — containers provide reproducibility, auto-scaling handles traffic spikes, and no server management is needed.
Common Misconception
✗ Serverless PHP (Lambda/Bref) is always the cheapest option — cold starts add latency, and consistent traffic is cheaper on containers; serverless excels at spiky, unpredictable workloads.
Why It Matters
Choosing the right deployment model determines scaling behaviour, cost, and operational complexity — a PHP app deployed on EC2 with manual scaling will go down under traffic spikes that ECS would handle automatically.
Common Mistakes
- PHP sessions on multiple EC2 instances without sticky sessions or Redis — session data lost on each request.
- Local file storage on containers — containers are ephemeral; use S3 for file storage.
- Not setting PHP-FPM worker count for container memory — match pm.max_children to available RAM.
- Bref for long-running PHP processes — Lambda has a 15-minute timeout; use ECS for queue workers.
Code Examples
✗ Vulnerable
// PHP on EC2 with local file storage — breaks on scale:
$uploadPath = '/var/www/html/uploads/' . $filename;
move_uploaded_file($_FILES['file']['tmp_name'], $uploadPath);
// Works on single server
// Behind load balancer: uploaded file only on one server
// User request may hit different server — file not found
✓ Fixed
// PHP on ECS Fargate with S3 for files:
// Dockerfile: FROM php:8.3-fpm-alpine
// Files go to S3, not local filesystem:
$s3->putObject([
'Bucket' => getenv('S3_BUCKET'),
'Key' => 'uploads/' . $filename,
'Body' => fopen($_FILES['file']['tmp_name'], 'r'),
]);
// Sessions in Redis — shared across all containers:
// session.save_handler = redis
// session.save_path = tcp://redis.internal:6379
Tags
🤝 Adopt this term
£79/year · your link shown here
Added
16 Mar 2026
Edited
22 Mar 2026
Views
20
🤖 AI Guestbook educational data only
|
|
Last 30 days
Agents 0
No pings yet today
No pings yesterday
Amazonbot 6
Perplexity 5
Unknown AI 3
Ahrefs 2
Google 1
Also referenced
How they use it
crawler 16
pre-tracking 1
⚡
DEV INTEL
Tools & Severity
🟡 Medium
⚙ Fix effort: High
⚡ Quick Fix
Use ECS Fargate with CodeDeploy blue/green — push Docker image to ECR, update task definition, CodeDeploy shifts traffic and rolls back automatically on health check failure
📦 Applies To
PHP 5.0+
web
cli
🔗 Prerequisites
🔍 Detection Hints
Manual SSH deployment; no rollback mechanism; downtime during deployments; no smoke test before traffic switch
Auto-detectable:
✗ No
aws-codedeploy
ecs
ecr
terraform
⚠ Related Problems
🤖 AI Agent
Confidence: Low
False Positives: Medium
✗ Manual fix
Fix: High
Context: File