This project follows a microservice-based architecture using containerized services:
- Nginx (Reverse Proxy): Handles incoming HTTP requests and routes them to PHP.
- PHP-FPM Application: Processes business logic and API endpoints.
- Prometheus: Collects metrics from the application.
- Grafana: Visualizes monitoring data.
- Docker Compose: Orchestrates multi-container setup.
- AWS EC2: Hosts the application publicly.
- Terraform: Provisions infrastructure (EC2 + Security Groups).
- (Optional) Kubernetes: Provides orchestration, scaling, and rolling updates.
- Each service runs in its own container.
- Dockerfile builds the PHP application.
- Docker Compose manages:
- PHP containers (scaled)
- Nginx proxy
- Monitoring stack (Prometheus + Grafana)
Advantages:
- Isolation of services
- Easy scaling (e.g., multiple PHP containers)
- Consistent environment across deployments
- Code is pushed to GitHub
- Workflow triggers:
- Pull latest code
- Build Docker images
- Deploy to EC2 via SSH
- Containers are updated using: docker compose up -d --build --scale php=2
- Terraform provisions:
- EC2 instance
- Security group (ports 80, 22)
Zero-downtime is achieved using:
- Multiple PHP containers (
--scale php=2) - Nginx load balances traffic between them
- During deployment:
- New containers are built and started
- Old containers are replaced gradually
(Optional with Kubernetes):
- Rolling updates ensure no downtime
- Traffic shifts gradually to new pods
- Application logs stored in
app.log - Docker logs available via: docker compose logs
- Prometheus collects metrics
- Grafana visualizes:
- Request rate
- Response time
- System performance
System can handle high load using:
- Multiple PHP containers (
--scale php=2or more) - Load distributed via Nginx
- Nginx is lightweight and high-performance
- PHP-FPM handles concurrent requests efficiently
- Prometheus tracks performance
- Grafana helps identify bottlenecks
- Add Redis caching
- Use Kubernetes HPA (auto-scaling)
- Add CDN (CloudFront)
- No hardcoded credentials
- Use environment variables / .env
- Use AWS IAM roles (recommended)
- Restrict SSH access in production
- Secrets can be managed via:
- AWS Secrets Manager
- HashiCorp Vault
You can test the deployed API directly from your browser:
curl -X POST http://35.154.99.46/data
-H "Content-Type: application/json"
-d '{"name":"test"}'
This project demonstrates a full DevOps pipeline including:
- Containerization (Docker)
- CI/CD (GitHub Actions)
- Monitoring (Prometheus + Grafana)
- Infrastructure as Code (Terraform)
- Optional orchestration (Kubernetes)