Building a Scalable WordPress Site on AWS
A two-tier WordPress deployment on AWS with a custom VPC, public and private subnets, security-group references and an isolated MariaDB server, all within the Free Tier.
When I first started learning AWS, I thought deploying a website meant just spinning up an EC2 instance and installing WordPress. But real-world cloud architecture is so much more than that. It’s about security, isolation, scalability, and following industry best practices.
In this article, I’ll walk you through how I built a secure, two-tier WordPress deployment on AWS from scratch — complete with a custom VPC, public and private subnets, proper security groups, and a completely isolated database server. And yes, you can see the live result here (if it’s still running!).
##What We’re Building
Here’s what the final architecture looks like:
- Custom VPC with public and private subnets
- WordPress server in the public subnet (accessible from internet)
- MariaDB database in the private subnet (completely isolated)
- Security groups controlling traffic between layers
- Internet Gateway for public access
- Everything within AWS Free Tier
Think of it as a mini production environment — the kind of setup you’d actually use for a real business website, not just a learning exercise.
##Why This Architecture Matters
Before we dive into the technical details, let’s talk about why we’re building it this way.
The Wrong Way (But Common)
Many tutorials show you how to install everything on a single EC2 instance:
- WordPress and MySQL on the same server
- Server has a public IP
- Database exposed to the internet (secured only by security groups)
- Everything in the default VPC
This works, but it’s not how you’d build anything in production. It’s like putting your entire house, including the safe with your valuables, right on the street.
The Right Way (What We’re Building)
Our architecture separates concerns:
- Web tier (public subnet): Handles user requests
- Database tier (private subnet): Stores data, completely isolated from internet
- Network isolation: Database cannot be accessed from internet, only from web server
- Defense in depth: Multiple security layers
This is how real companies structure their infrastructure. It’s more secure, more scalable, and follows AWS Well-Architected Framework principles.
##Part 1: Building the Network Foundation
Every good AWS deployment starts with proper networking. We’re not using the default VPC, we’re building our own from scratch.
Creating the VPC
First, I created a VPC with the CIDR block 10.0.0.0/16. This gives us 65,536 IP addresses to work with; way more than we need, but it allows for future growth.
VPC: wordpress-vpc
CIDR: 10.0.0.0/16
Region: us-east-2 (Ohio)
Why a custom VPC? Because the default VPC is shared across all your projects. A custom VPC gives you complete control and isolation.
The Two Subnets
Here’s where it gets interesting. I created two subnets in different address ranges:
Public Subnet (10.0.1.0/24)
- Houses the WordPress web server
- Has a route to the Internet Gateway
- Auto-assigns public IPs to instances
- Users can reach servers here from the internet
Private Subnet (10.0.2.0/24)
- Houses the database server
- No route to the Internet Gateway
- No public IPs assigned
- Completely isolated from direct internet access
The difference between public and private isn’t just a label, it’s defined by routing. The public subnet has a route that says “send internet traffic (0.0.0.0/0) to the Internet Gateway.” The private subnet doesn’t have this route.
Setting Up the Internet Gateway
An Internet Gateway is like the front door of your VPC. I created one and attached it to the VPC, then updated the public route table to send all internet-bound traffic through it.
Without this, even instances in the “public” subnet wouldn’t be able to talk to the internet.
##Part 2: Security Groups: The Firewall Layer
Security groups are AWS’s way of controlling traffic. Think of them as virtual firewalls attached to each instance.
WordPress Server Security Group (wordpress-web-sg)
Inbound Rules:
- HTTP (80) from 0.0.0.0/0; anyone can view the website
- HTTPS (443) from 0.0.0.0/0; for secure connections
- SSH (22) from my IP only; administrative access locked down
Outbound Rules:
- All traffic allowed, the server needs to download updates, talk to the database, etc.
Database Server Security Group (wordpress-db-sg)
Here’s where it gets smart:
Inbound Rules:
- MySQL (3306) from wordpress-web-sg only, not from an IP address, but from the WordPress security group
- SSH (22) from wordpress-web-sg, for administrative access
This is crucial. By referencing the WordPress security group instead of an IP address, the rule automatically applies to any instance with that security group. If the WordPress server’s IP changes or we add more web servers, we don’t need to update the database firewall.
##Part 3: Launching the Database Server
Now for the first EC2 instance: the database server.
The Challenge: How Do You Access a Server with No Public IP?
This was my first real challenge. I launched a t3.micro instance in the private subnet with no public IP. Great for security, but now I couldn’t SSH to it from my laptop!
Initial Attempt: AWS Systems Manager Session Manager I tried using Session Manager, which lets you access instances through the AWS Console without SSH. But I got an error: “SSM Agent is not online.”
Why? Because Session Manager requires the instance to reach AWS Systems Manager endpoints on the internet. But my database server is in a private subnet with no internet access. Catch-22!
The Solution: Bastion Host I used the WordPress server (which I launched next) as a “bastion host” a jump server. The flow looked like this:
I converted my PuTTY .ppk key to .pem format, copied it to the WordPress server, and SSH’d from there to the database using its private IP: 10.0.2.170.
Installing MariaDB
Once connected, I ran into another surprise. Amazon Linux 2023 doesn’t have MySQL packages!
sudo yum install mysql-server -y
# Error: No match for argument: mysql-server
Turns out Amazon Linux 2023 ships with MariaDB instead. It’s a MySQL fork that’s fully compatible with WordPress, so I installed that:
sudo yum install mariadb105-server -y
sudo systemctl start mariadb
sudo systemctl enable mariadb
Securing the Database
I ran mysql_secure_installation to:
- Set a strong root password
- Remove anonymous users
- Disable remote root login
- Remove test databases
Then created the WordPress database and user:
CREATE DATABASE wordpress_db;
CREATE USER 'wordpress_user'@'%' IDENTIFIED BY 'StrongPassword123!';
GRANT ALL PRIVILEGES ON wordpress_db.* TO 'wordpress_user'@'%';
FLUSH PRIVILEGES;
The Critical Configuration Change
By default, MariaDB only listens on localhost (127.0.0.1). This is secure, but it means our WordPress server on a different machine can’t connect!
I edited /etc/my.cnf.d/mariadb-server.cnf and added:
[mysqld]
bind-address = 0.0.0.0
This tells MariaDB to listen on all network interfaces. Sounds scary, but remember:
- The database is in a private subnet (no internet access)
- Security groups only allow traffic from the WordPress server
- No public IP address
- Strong password authentication
After restarting MariaDB, I verified it was listening on all interfaces:
sudo netstat -tlnp | grep 3306
# tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN
Perfect!
##Part 4: The WordPress Server
Now for the public-facing server. I launched another t3.micro instance, this time in the public subnet with a public IP: 18.221.105.18.
Installing the LAMP Stack
sudo yum update -y
sudo yum install httpd -y # Apache web server
sudo yum install php php-mysqlnd php-fpm php-json php-gd php-mbstring php-xml -y
sudo systemctl start httpd
sudo systemctl enable httpd # Start on boot
Installing WordPress
cd /tmp
wget https://wordpress.org/latest.tar.gz
tar -xzf latest.tar.gz
sudo cp -r wordpress/* /var/www/html/
sudo chown -R apache:apache /var/www/html/
sudo chmod -R 755 /var/www/html/
The Configuration File
I created wp-config.php from the sample file and updated the database settings. Here's the critical part:
define( 'DB_NAME', 'wordpress_db' );
define( 'DB_USER', 'wordpress_user' );
define( 'DB_PASSWORD', 'StrongPassword123!' );
define( 'DB_HOST', '10.0.2.170' ); // Private IP of database server
Notice we’re using the private IP (10.0.2.170), not “localhost” or the public IP. The WordPress server connects to the database through the VPC’s internal network.
Testing Connectivity
Before accessing WordPress in the browser, I tested the database connection manually:
mysql -h 10.0.2.170 -u wordpress_user -p
# Enter password...
# MariaDB [(none)]>
Success! The two servers could communicate.
##Part 5: The Gateway Timeout Mystery
I opened my browser, navigated to http://18.221.105.18, and… gateway timeout error.
Not what I expected.
Troubleshooting
I worked through this systematically:
Layer 1: Web Server
sudo systemctl status httpd
# Active: active (running) ✓
Apache was running fine.
Layer 2: WordPress Files
ls -la /var/www/html/wp-config.php
# File exists ✓
Layer 3: Database Connection
mysql -h 10.0.2.170 -u wordpress_user -p
# Connection works ✓
Wait, the connection worked from the command line but not from WordPress?
The Problem: I realized I had initially set up the database security group with an IP-based rule (10.0.1.0/24) but then tried to change it to reference the WordPress security group. AWS threw an error: “You may not specify a referenced group id for an existing IPv4 CIDR rule.”
The Fix: Security group rules are immutable. I had to:
- Delete the old MySQL rule completely
- Add a new rule referencing wordpress-web-sg
After this change, I refreshed the browser and saw… the WordPress installation wizard!
##Part 6: WordPress Installation
The browser-based installation was straightforward:
- Selected language
- Entered site details:
- Site title: “My AWS WordPress Site”
- Username: admin
- Strong password
- Email address
- Clicked “Install WordPress”
Within seconds, I was logged into the WordPress dashboard.
To verify everything worked, I:
- Created a test post (you can see it here if the server is still running)
- Uploaded an image to the media library
- Checked the database tables were created correctly
All the data was being stored on the database server in the private subnet, exactly as designed.
##What I Learned
This project taught me more than just “how to install WordPress on AWS.” Here are the key takeaways:
1. Network Architecture is Everything
The difference between public and private subnets isn’t cosmetic — it’s fundamental to security. By isolating the database in a private subnet, we eliminated an entire class of attacks.
2. Security Groups are Powerful
Using security group references instead of IP addresses makes your infrastructure more flexible and secure. When you scale to multiple web servers, they all automatically get database access without updating firewall rules.
3. Troubleshooting is a Skill
When I got the gateway timeout error, I didn’t panic. I tested each layer systematically: web server → files → network → database. This methodical approach quickly identified the security group issue.
4. Default Configurations Prioritize Security
MariaDB binding to localhost by default, security groups denying all traffic by default, these aren’t bugs, they’re features. AWS assumes you want security and makes you explicitly open things up.
5. Documentation Can Be Outdated
Many tutorials assume Amazon Linux 2, but Amazon Linux 2023 made significant changes (like removing MySQL packages). Always verify commands work on your specific OS version.
##How to Make This Production-Ready
While this setup is great for learning, here’s what I’d change for a real production website:
High Availability
- Deploy across multiple Availability Zones
- Use an Application Load Balancer
- Implement Auto Scaling (automatically add servers under heavy load)
Database Improvements
- Migrate to Amazon RDS with Multi-AZ (automatic failover in ~60 seconds)
- Enable automated backups with point-in-time recovery
- Add read replicas for scaling
Content Delivery
- Use Amazon CloudFront CDN for faster global access
- Store media files in Amazon S3
- Implement Amazon EFS for shared WordPress files across multiple servers
Security Enhancements
- Add SSL/TLS certificate (HTTPS)
- Implement AWS WAF (Web Application Firewall) to block attacks
- Use AWS Secrets Manager for database credentials
- Enable VPC Flow Logs for monitoring
Monitoring and Alerts
- Set up CloudWatch alarms (high CPU, disk space, downtime)
- Implement application performance monitoring
- Configure SNS for instant alerts
Static IP
- Use an Elastic IP instead of dynamic public IP
- Or better yet, use a domain name via Route 53
##Live Demo
Check out the live result: http://18.221.105.18
(Note: This is a learning project on the free tier, so I may shut down the instances to avoid charges. If the link doesn’t work, the server is offline, but the architecture and lessons remain valid!)
##Final Thoughts
Building this WordPress deployment taught me that cloud architecture isn’t just about making things work — it’s about making them work securely and scalably.
The extra effort to create separate subnets, configure security groups properly, and isolate the database might seem like overkill for a simple blog. But these practices become critical when you’re handling customer data, processing payments, or running a business.
Every production-grade application I’ve seen follows similar patterns: public web tier, private application tier, isolated database tier. Learning this architecture on a small WordPress site gives you skills that transfer directly to enterprise environments.
What started as an assignment became a real lesson in thinking like a cloud architect. And that’s worth way more than just getting WordPress installed.