Looking to host a fast, secure, and scalable WordPress site on AWS? In this step-by-step tutorial, weβll walk you through how to set up WordPress using Amazon CloudFront, an Application Load Balancer (ALB), and private subnetsβperfect for both test and production environments.
Using our demo domain wp.ituptodate.com
, this guide is ideal for beginners looking to build a modern WordPress setup using AWS best practices and PHP 8.1.
π Why Use CloudFront, ALB, and Private Subnets for WordPress?
Hereβs why this combination is powerful for WordPress hosting on AWS:
- πΉ Amazon CloudFront: A global Content Delivery Network (CDN) that dramatically improves your website speed by caching content closer to users.
- πΉ Application Load Balancer (ALB): Distributes incoming traffic across servers for better performance and uptime.
- πΉ Private Subnets: Keep your WordPress server isolated from the public internet for better security. Access it only through ALB and CloudFront.
π‘ Result: A secure, high-performance, production-ready WordPress website thatβs optimized for both speed and scalability.
β Prerequisites
Before we dive in, make sure you have:
- An AWS account with IAM permissions for EC2, VPC, ALB, and CloudFront.
- A registered domain (like
wp.ituptodate.com
), preferably managed via Cloudflare. - A basic understanding of VPC, subnets, EC2, and WordPress setup.
- A MySQL database (AWS RDS or local EC2).
- PHP 8.1 installed on your EC2 instance.
π§ Step 1: Set Up Your VPC and Subnets
Start by creating a strong AWS network foundation.
π οΈ VPC Settings:
- CIDR Block:
10.0.0.0/16
- Region: Choose your nearest AWS region (e.g.,
ap-south-1
for Mumbai)
π Subnets:
- Public Subnet:
10.0.1.0/24
(for ALB) - Private Subnet:
10.0.2.0/24
(for WordPress EC2)
π¦ Route Tables:
- Public subnet β Connect to an Internet Gateway
- Private subnet β Route via EC2 (for testing) or NAT Gateway (for production)
π Security Groups:
Allow HTTP (80) and HTTPS (443).
π‘ Budget Tip: Use a free-tier EC2 instance as a NAT for testing to save costs.
π₯οΈ Step 2: Launch EC2 and Install WordPress
π Launch Your Instance:
- Place it in the private subnet.
- Use a free-tier EC2 (e.g., t2.micro) for testing.
π₯ Install WordPress & PHP:
sudo apt update
sudo apt install nginx php8.1-fpm php8.1-mysql -y
sudo mkdir -p /var/www/html
cd /var/www/html
sudo wget https://wordpress.org/latest.tar.gz
sudo tar -xzf latest.tar.gz --strip-components=1
βοΈ Configure WordPress:
- Edit
wp-config.php
with your MySQL database credentials.
βΆοΈ Start Services:
sudo systemctl start nginx php8.1-fpm
sudo systemctl enable nginx php8.1-fpm
π Step 3: Set Up Application Load Balancer (ALB)
π§ Create ALB:
- Scheme: Internet-facing
- Subnet: Public
- Listeners: HTTP (80) β Redirect to HTTPS (443)
π― Target Group:
- Name:
wordpress-tg
- Target: Your EC2 instance (e.g.,
10.0.60.51
) - Health Check:
/
or/info.php
π Add SSL:
- Request an ACM certificate for
wp.ituptodate.com
inap-south-1
- Attach to HTTPS:443 listener
β‘ Step 4: Boost Speed with Amazon CloudFront
π Create CloudFront Distribution:
- Origin: ALB DNS (e.g.,
cloudfront-alb2-xyz.elb.amazonaws.com
) - Viewer Protocol Policy: Redirect HTTP to HTTPS
- Origin Protocol Policy: Match Viewer
π SSL Setup:
- Request an ACM certificate in us-east-1 for CloudFront
- Add
wp.ituptodate.com
as an Alternate Domain Name (CNAME)
π Step 5: Point DNS to CloudFront Using Cloudflare
π οΈ Add a CNAME Record:
- Name:
wp.ituptodate.com
- Value: CloudFront domain (e.g.,
d30wa1yxgmf3fs.cloudfront.net
) - Proxy: Enabled (orange cloud)
π Cloudflare SSL Settings:
- Set SSL/TLS Mode to Full (strict)
π οΈ Step 6: Fix Common Issues
β 504 Gateway Timeout?
Check health checks. Restart Nginx and PHP:
sudo systemctl restart nginx php8.1-fpm
π 301 Redirect Loop?
Add to wp-config.php
:
if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') {
$_SERVER['HTTPS'] = 'on';
}
Remove any duplicate redirect rules from Nginx or .htaccess
.
π SSL Not Working?
Make sure:
- Certificates are issued
- Correct regions:
us-east-1
for CloudFront,ap-south-1
for ALB
β Step 7: Complete WordPress Setup
- Visit: https://wp.ituptodate.com
- Run the WordPress installation wizard
- Set permalinks: Settings > Permalinks > Save
π Best Practices for WordPress on AWS
- π Use HTTPS only β remove HTTP listener after setup.
- π Optimize caching with CloudFront cache policies.
- πΌ Upgrade from EC2 NAT to AWS NAT Gateway for production.
- π Monitor logs for ALB and CloudFront regularly.
π Conclusion
Congratulations! π Youβve successfully set up a modern, secure, and high-speed WordPress website on AWS using CloudFront, ALB, and private subnets. Whether you’re building a test environment or a production-ready blog or business site, this setup ensures speed, scalability, and security.
π§ Want more tutorials like this? Keep visiting ITUptodate.com for practical cloud, DevOps, and WordPress hosting guides!
No Comments
Leave a comment Cancel