Hands-on AWS project · us-east-1 · Amazon Linux 2023 · WordPress on Apache + PHP
A typical WordPress tutorial puts the site, the database and the uploads on one server. That server is then a single point of failure, a security target and a scaling wall, all at once. This project fixes each problem by design: split the system into three tiers, give every tier its own network zone, and keep the servers stateless so any of them can be lost or replaced.
By the end you will know what each AWS building block does, why it sits where it does, which mistakes are easy to make, and how to tear everything down without leaving a bill behind.
Why three tiers?
Each tier has one job and one trust level, and it is reachable only from the tier before it.
| Tier | Components | Exposure | Why separate |
|---|---|---|---|
| Presentation | Internet Gateway, ALB, NAT gateways | Public | The only layer that must face the internet, so everything else can hide |
| Application | 2 × EC2 running Apache + PHP | Private | Runs the code; can be replaced or multiplied without data loss |
| Data | RDS MySQL, EFS | Private | Holds all state, so the servers don't have to |
Key idea: stateless servers. If a server stores nothing that matters (no database, no uploads), then losing it costs nothing, and adding a second one is just a copy. Moving state to RDS and EFS is what makes the rest of the design possible.
Follow one request
- DNS. The browser resolves the
MyALBname to the load balancer's public addresses, one in each public subnet. - Edge. The Internet Gateway carries the packet into the VPC.
ALBSecurityGroupadmits it on port 80. - Balance. The ALB chooses a healthy target from
MyAppServersand forwards to its private IP. The server accepts because the traffic comes from the ALB's security group. - Files. Apache runs PHP from
/var/www/html, which is the shared EFS volume. - Data. PHP queries RDS on port 3306. The database accepts only the web servers' security group.
- Reply. The page returns along the same path. The servers never hold a public IP; they only call out, through NAT, for updates.
Build order: VPC › Subnets › IGW + NAT + routes › Security groups › RDS + EFS › Setup server › App servers › ALB + target group › URL cutover › Clean-up
1. Network foundation
MyVPC is a private slice of AWS with the range 10.0.0.0/16, which means 65,536 addresses. DNS resolution and DNS hostnames are enabled, because EFS is mounted by its DNS name. Inside it, six /24 subnets of 256 addresses each (AWS reserves 5 per subnet) are spread over two Availability Zones, which are physically separate data centers.
| Subnet | CIDR | AZ | Tier |
|---|---|---|---|
PublicSubnet1 / 2 | 10.0.0.0/24 · 10.0.1.0/24 | 1a / 1b | Presentation |
PrivateAppSubnet1 / 2 | 10.0.2.0/24 · 10.0.3.0/24 | 1a / 1b | Application |
PrivateDBSubnet1 / 2 | 10.0.4.0/24 · 10.0.5.0/24 | 1a / 1b | Data |
Creating MyVPC with a /16 block, leaving room to add more subnets later.
The six subnets, named by tier so the console stays readable.
"Public" and "private" are just routing
No setting on a subnet says "public". A subnet is public only if its route table sends 0.0.0.0/0 (all non-local traffic) to an Internet Gateway. Here is the whole routing plan:
| Route table | Attached to | Default route (0.0.0.0/0) |
|---|---|---|
PublicRouteTable | PublicSubnet1, PublicSubnet2 | Internet Gateway (MyIGW) |
PrivateRouteTableAZ1 | PrivateAppSubnet1, PrivateDBSubnet1 | NAT Gateway 1 |
PrivateRouteTableAZ2 | PrivateAppSubnet2, PrivateDBSubnet2 | NAT Gateway 2 |
IGW vs NAT. An Internet Gateway is two-way: the internet can reach a resource that has a public IP. A NAT Gateway is one-way: private servers can start connections out (to download Apache and PHP packages) but nothing outside can start one in. The NAT Gateway itself lives in a public subnet because it needs a route to the IGW, and it gets an Elastic IP as its fixed public address. Using one NAT per AZ means a zone failure doesn't strand the other zone's updates, and avoids cross-AZ data charges.
PublicRouteTable: 10.0.0.0/16 stays local, everything else goes to the Internet Gateway.
NAT Gateway 1: zonal, public connectivity, placed in PublicSubnet1 with its own Elastic IP.
PrivateRouteTableAZ1 points its default route at the NAT Gateway instead of the IGW.
2. Security: each layer trusts only the one above
A security group is a firewall attached to a resource. It is stateful (replies to allowed traffic are let back automatically), it only has allow rules, and everything inbound is denied until you allow it. The key trick here is that a rule's source can be another security group instead of an IP range.
Security group chaining: each tier accepts traffic only from the group of the tier above it.
Read the rule on the web servers as: "accept port 80 only from resources wearing the ALB badge." That gives two benefits. Nobody can bypass the load balancer to hit a server directly, and the rule never goes stale when the ALB's IP addresses change, since it names a group, not an address. The EFS group also references itself so its mount targets can talk to each other.
WebServerSecurityGroup: the sources are security group IDs (the ALB group, plus the SSH group for setup).
Why not reuse one group everywhere? If the servers wore the ALB's group they would accept traffic from the whole internet, which defeats hiding them. One group per tier is what makes least-privilege possible.
3. Data: RDS for records, EFS for files
| RDS MySQL | Amazon EFS | |
|---|---|---|
| Stores | Posts, users, comments, settings | WordPress core, themes, plugins, uploads |
| Why managed | Backups, patching and encryption handled by AWS | Elastic capacity, multi-AZ by design, no disks to size |
| Access | SQL over port 3306 | NFS over port 2049 |
The database
The instance is MySQL 8.4 on db.t4g.micro (Free Tier template, 20 GiB, encryption on, 1-day backups), with Public access: No. RDS requires a DB subnet group covering at least two AZs. Putting only the two PrivateDB subnets in it guarantees the database can never land in a public subnet. I created an initial database called mydatabase, which WordPress later connects to.
The DB subnet group lists only the two data-tier subnets.
No public access, and only DatabaseSecurityGroup (web servers on 3306) can connect.
The file system
An EBS disk attaches to one instance in one AZ, so it can't be shared. Without a shared drive, a plugin installed via server 1 would be missing on server 2, and visitors would see broken pages depending on where the load balancer sent them. EFS is a network file system that both servers mount at the same path, so every file is identical everywhere. One mount target per AZ sits behind EFSSecurityGroup.
MyEFS, encrypted. EFS bills for the data actually stored.
Trade-off to know. PHP reads many small files, and network storage adds latency compared with a local disk. Production sites usually add PHP OPcache, an object cache, or move media to S3 with a CDN.
4. Compute: install once, serve from two
Private servers can't be reached from a browser, so I used a two-step plan.
Step 1: a temporary setup server
Webserver-Instance (t3.micro, Amazon Linux 2023) went into a public subnet with a public IP and three groups: WebServer, SSH (my IP only) and ALB. From it I:
- Created
/var/www/htmland mounted EFS with NFS 4.1 (mkdir -pfirst, as root). - Installed Apache and confirmed it was active with
systemctl is-active httpd. - Downloaded WordPress into the EFS volume and set ownership and permissions (
chmod 2775on directories,0664on files). - Edited
wp-config.php: database name, user, and the RDS endpoint asDB_HOST. - Ran the five-minute WordPress installer in the browser.
Because files and data both live outside the machine, that one install became the install for every server created afterwards.
What the mount options mean.
nfsvers=4.1picks the protocol.hardmakes the client retry forever instead of failing a write mid-request.noresvportlets it reconnect from a new source port after a network hiccup. The leading2in2775is the setgid bit, so new files inherit theapachegroup.
EFS appears as an 8.0E (effectively unlimited) volume mounted at /var/www/html.
Step 2: two private application servers
ApplicationServer1 (1a) and ApplicationServer2 (1b) were launched in the private app subnets with Auto-assign public IP: Disable and only WebServerSecurityGroup. A User Data script, which runs once as root at first boot, installed Apache and PHP via the NAT gateway and mounted the same EFS path. A representative script:
#!/bin/bash dnf install -y httpd php php-mysqlnd amazon-efs-utils nfs-utils mkdir -p /var/www/html echo "<EFS-ID>.efs.us-east-1.amazonaws.com:/ /var/www/html nfs4 nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport,_netdev 0 0" >> /etc/fstab mount -a systemctl enable --now httpd The /etc/fstab line makes the mount survive reboots, and _netdev tells the OS to wait for the network first.
5. Load balancing and the cutover
What an ALB does. It works at layer 7 (it understands HTTP), listens on a port, and forwards to a target group, a pool of servers it health-checks. It places a node in each subnet you choose, so it survives an AZ outage too. Unhealthy targets simply stop receiving requests.
The target group MyAppServers (instances, HTTP:80, health check path /) holds the two application servers, deliberately not the setup server. MyALB is internet-facing, mapped to both public subnets, protected by ALBSecurityGroup, with an HTTP:80 listener forwarding to that group. Both targets went Healthy, one per AZ.
Both servers pass health checks, one in each Availability Zone.
The URL trap. WordPress saves its own address in the database. After installing through the setup server's IP, every link and redirect still pointed there. I set both WordPress Address and Site Address (Settings → General) to the ALB's DNS name. Skip this and visitors get bounced to a server that no longer exists.
The proof
I stopped, then terminated, Webserver-Instance and refreshed the ALB address. The site still loaded, which proves requests flow ALB → private servers → EFS and RDS with nothing hidden behind the scenes.
Setup server stopped; both private servers running with all checks passed.
"My AWS 3-Tier Site" served through MyALB.
What went wrong, and how it was fixed
| Symptom | Cause and fix |
|---|---|
| SSH: "Server refused our key" | The login wasn't set up with the right user and key. Connecting as ec2-user with the key pair worked. |
mount point /var/www/html does not exist | Fresh AMIs lack the folder. Switch to root, mkdir -p /var/www/html, mount again. |
| WordPress can't reach the database | DB_HOST was still localhost. Use the RDS endpoint and restart Apache. |
| Targets show "Unused" | The target group had no load balancer yet. Once MyALB used it, health checks ran. |
| Browser shows "Not secure" | Only an HTTP:80 listener exists (next section). |
Why the browser says "Not secure"
You can't attach a public certificate to an elb.amazonaws.com name, because AWS owns that domain. To get HTTPS: point a custom domain at MyALB (Route 53 alias), request a free ACM certificate in us-east-1 with DNS validation, allow port 443 on ALBSecurityGroup, add an HTTPS:443 listener with the certificate, redirect 80 to 443, and update the WordPress URLs to https://yourdomain.com.
Expected on a lab ALB with no certificate.
Questions this design answers
What happens if Availability Zone 1a fails?
The ALB's health checks mark ApplicationServer1 unhealthy and send all traffic to ApplicationServer2. EFS is built across zones, so files stay available. The database is the weak spot: it runs as a single instance, so pages that need it would fail until it is restored. Enabling Multi-AZ removes that gap.
Why is the load balancer public but the servers private?
Visitors need one door, not many. Keeping servers private removes direct attacks, SSH exposure and stray public IPs. The ALB is the only thing that has to be hardened and watched.
How would this scale?
Because servers are stateless, scaling out means launching more copies from a template and registering them in the target group. An Auto Scaling group automates this and also replaces failed instances.
What costs money while it runs?
NAT Gateways and the load balancer bill per hour whether or not traffic flows, and NAT also bills for data processed. Unattached Elastic IPs bill too. These are why the clean-up order matters.
Next steps for production
- HTTPS with ACM and a custom domain, then CloudFront and WAF.
- Multi-AZ RDS (the subnet group is already prepared).
- Auto Scaling with a launch template instead of hand-built servers.
- Secrets Manager for database credentials instead of plain text in
wp-config.php. - S3 for media and caching to reduce load on EFS.
Clean-up without surprise bills
Order matters, because AWS blocks deletes that still have dependants:
- ALB and target group. Delete
MyALB, thenMyAppServers. - EC2. Terminate both application servers and the setup server.
- RDS and EFS. Delete the database (skip the final snapshot and retained backups) and the file system.
- NAT. Delete both NAT Gateways, then release their Elastic IPs. Deleting a NAT Gateway does not release its IP.
- DB subnet group. Delete the custom group.
- VPC. Delete
MyVPC, which removes its IGW, subnets, route tables and custom security groups. Check IAM for leftover roles. - Verify. Check Elastic IPs, EBS volumes and snapshots, RDS snapshots and the Billing dashboard.
Takeaways
Three-tier is a discipline more than a number: give each component the least access it needs, and never keep anything important on a machine you can't afford to lose. Chained security groups made the network self-documenting, moving state to RDS and EFS made servers disposable, and the real test was terminating the setup server and watching the site stay up.

















