AWS infrastructure for hosting multiple WordPress and Laravel sites using Terraform, Ansible, and Docker.
This project migrates several production websites from a traditional VPS to AWS. While a VPS was sufficient for running the sites, the goal was to gain hands-on experience with modern DevOps practices:
- Infrastructure as Code with Terraform
- Configuration Management with Ansible
- Containerization with Docker
- AWS Services (EC2, RDS, ALB, ECR, SSM)
There are simpler ways to host sites on AWS (Elastic Beanstalk, Lightsail) and more sophisticated ones (ECS/Fargate, Kubernetes). This architecture sits in the middle:
| Approach | Cost | Complexity | Learning Value |
|---|---|---|---|
| AWS Lightsail | $ | Low | Limited |
| This Project | $$ | Medium | High |
| ECS/Fargate | $$$ | Medium-High | High |
| Kubernetes (EKS) | $$$$ | High | Very High |
The result is a cost-effective setup (~$70/month for 8 sites) that provides real experience with AWS, Terraform, and Ansible without the overhead of container orchestration platforms.
┌─────────────────────────────────────────────────────────────────┐
│ Cloudflare │
│ (DNS + Proxy) │
└────────────────────────────┬────────────────────────────────────┘
│
┌────────────────────────────▼────────────────────────────────────┐
│ Application Load Balancer │
│ (SSL termination, routing) │
└────────────────────────────┬────────────────────────────────────┘
│
┌────────────────────────────▼────────────────────────────────────┐
│ EC2 + Docker Compose │
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
│ │WordPress │ │WordPress │ │ Laravel │ │ Laravel │ ... │
│ │ + nginx │ │ + nginx │ │ + nginx │ │ + nginx │ │
│ └──────────┘ └──────────┘ └──────────┘ └──────────┘ │
└────────────────────────────┬────────────────────────────────────┘
│
┌────────────────────────────▼────────────────────────────────────┐
│ RDS MySQL │
│ (shared database) │
└─────────────────────────────────────────────────────────────────┘
- WordPress - PHP-FPM with WP-CLI, persistent uploads/themes/plugins
- Laravel - PHP-FPM with queue workers and scheduler
- Static - S3 + CloudFront distribution
.
├── terraform/ # AWS infrastructure (VPC, EC2, RDS, ALB)
├── ansible/ # Server configuration and deployment
└── docker/images/ # Custom Docker images for ECR
1. Provision Infrastructure
cd terraform/projects/shared-hosting
terraform init
terraform apply2. Deploy Applications
cd ansible
ansible-playbook playbooks/deploy.yml| Component | Documentation |
|---|---|
| Infrastructure | terraform/README.md |
| Deployment | ansible/README.md |
| Docker Images | docker/images/README.md |
- Terraform - Infrastructure provisioning
- Ansible - Configuration management via AWS SSM
- Docker Compose - Container orchestration
- AWS - EC2, RDS, ALB, ECR, S3, CloudFront, SSM
Current: ~$70/month for 8 production sites
Exploring optimizations like right-sizing instances based on actual usage metrics.
This infrastructure is actively maintained and serves production traffic.