This project contains Terraform code to deploy a simple LAMP (Linux, Apache, MySQL, PHP) server on AWS.
- Terraform installed on your local machine
- AWS account with appropriate permissions
- AWS CLI configured with your credentials
-
Clone and Navigate to the
iac
folder:git clone https://github.com/dansarpong/lamp-lab.git cd lamp-lab
-
Set the DB credentials:
aws secretsmanager create-secret \ --profile <profile_name> \ --name db-creds-v1 \ --description "Credentials for my LAMP stack DB" \ --secret-string '{"username": "user", "password": "pass"}' \ --tags Key=Lab,Value=LAMP
-
Initialize Terraform:
terraform init
-
Set the AWS credentials as environment variables if not already set in default profile:
export AWS_PROFILE=<profile_name>
-
Plan the deployment:
terraform plan
-
Apply the deployment:
terraform apply
-
Confirm the deployment:
- Type
yes
when prompted to confirm the deployment.
- Type
After the deployment is complete, Terraform will output the public IP address of the LAMP server. You can use this IP address to access the server via a web browser after a few minutes.
To destroy the resources created by Terraform, run:
terraform destroy
Then run the following command to delete the secret:
aws secretsmanager delete-secret \
--profile <profile_name> \
--secret-id db-creds-v1 \
--recovery-window-in-days 7
- Scalability
- Autoscaling Group (ASG) scales from 1 to 4 t3.micro instances based on CPU utilization (scale up at >70%, down at <30%)
- Application Load Balancer distributes traffic across instances in multiple Availability Zones
- Security
- RDS is in private subnets, not publicly accessible, and encrypted at rest
- EC2 instances are in public subnets but restricted via security groups (SSH limited to EC2 Instance Connect, HTTP limited to ALB).
- Database credentials are stored in AWS Secrets Manager
- Availability
- RDS uses Multi-AZ for automatic failover
- EC2 instances and ALB span two Availability Zones for availability
- RDS automated backups retained for 5 days with a daily backup window
- ALB performs HTTP health checks on instances to ensure they are healthy
- Traffic Loads
- Designed for light to moderate traffic (e.g., hundreds of users)
- Autoscaling Group can handle increased traffic by adding more instances
- Performance Needs
- 'db.t3.micro' instances are suitable for light workloads
- ALB optimizes request routing to healthy instances
- Security Levels
- RDS is encrypted at rest and not publicly accessible
- EC2 instances are secured via security groups and SSH access is restricted
- Database credentials are stored in AWS Secrets Manager