Home/Blog/How to Autoscale Your WordPress Site on AWS
Aws

How to Autoscale Your WordPress Site on AWS

WordPress powers over 27% of websites globally, making it the world’s most popular content management system. While managed WordPress hosting offers simplicity, businesses often need more control, cus...

How to Autoscale Your WordPress Site on AWS

This comprehensive guide walks you through designing and implementing a production-ready WordPress infrastructure on AWS that scales automatically with your traffic while optimizing costs.

Infrastructure Design Principles

Before architecting any cloud infrastructure, evaluate these four critical questions to ensure your design meets business requirements:

  • Scalability: Can the architecture handle expected traffic growth and sudden spikes?
  • Availability: Does the design meet your Service Level Objectives (SLO) for uptime?
  • Simplicity: Is the solution as simple as possible while meeting requirements?
  • Cost Efficiency: Does the architecture optimize costs without sacrificing performance?

💡 Single Instance Reality Check: A single WordPress server on AWS EC2 provides 99.99% uptime, meaning approximately 11 hours of downtime per year. If this meets your business requirements, a simpler architecture may be more cost-effective.

Scalable WordPress Architecture on AWS

Our recommended architecture eliminates single points of failure while providing automatic scaling and cost optimization through intelligent traffic distribution and caching strategies.

Diagram illustrating AWS architecture for autoscaling, featuring internet gateway, load balancer, and auto-scaling group integration.

Architecture Components

  • CloudFront CDN: Global content delivery network that caches static content closer to users, reducing server load and improving performance
  • Application Load Balancer (ALB): Distributes incoming traffic across multiple EC2 instances with health checks
  • Auto Scaling Group: Automatically launches or terminates EC2 instances based on traffic patterns and performance metrics
  • Amazon RDS: Managed MySQL database service providing automated backups, maintenance, and high availability
  • Amazon EFS: Shared file system for wp-content folder, accessible across all EC2 instances

Data Persistence Strategy

WordPress requires two types of persistent data: the application code and user-generated content. Our architecture handles these differently for optimal performance:

  • WordPress Core Files: Baked into custom AMI (Amazon Machine Image) for fast instance launches
  • wp-content Directory: Stored on Amazon EFS for shared access across all instances
  • Database: Managed by Amazon RDS with automated backups and multi-AZ deployment

🔄 Alternative Storage Option: Consider Amazon S3 for wp-content storage instead of EFS. While requiring a WordPress plugin, S3 can reduce server load and costs for sites with heavy media usage. Learn more about CDN optimization.

Step-by-Step Configuration

Follow these sequential steps to build your autoscaling WordPress infrastructure. Each component builds upon the previous configuration, so maintain the order for successful deployment.

1. Create MySQL RDS Database Instance

Set up a managed MySQL database that will serve all WordPress instances:

# AWS CLI command to create RDS instance
aws rds create-db-instance \
    --db-instance-identifier wordpress-db \
    --db-instance-class db.t3.micro \
    --engine mysql \
    --master-username admin \
    --master-user-password YourSecurePassword123 \
    --allocated-storage 20 \
    --vpc-security-group-ids sg-xxxxxxxxx \
    --db-subnet-group-name wordpress-subnet-group

→ Complete RDS MySQL setup guide

2. Configure VPC and Subnets

Create dedicated subnets for your EC2 instances across multiple Availability Zones:

# Create subnet in first AZ
aws ec2 create-subnet \
    --vpc-id vpc-xxxxxxxxx \
    --cidr-block 10.0.1.0/24 \
    --availability-zone us-east-1a

# Create subnet in second AZ
aws ec2 create-subnet \
    --vpc-id vpc-xxxxxxxxx \
    --cidr-block 10.0.2.0/24 \
    --availability-zone us-east-1b

→ VPC and subnet configuration guide

3. Provision Amazon EFS File System

Set up shared storage for WordPress wp-content directory:

# Create EFS file system
aws efs create-file-system \
    --creation-token wordpress-efs-$(date +%s) \
    --performance-mode generalPurpose \
    --encrypted

# Create mount targets in each subnet
aws efs create-mount-target \
    --file-system-id fs-xxxxxxxxx \
    --subnet-id subnet-xxxxxxxxx \
    --security-groups sg-xxxxxxxxx

→ EFS setup and configuration guide

4. Build Custom WordPress AMI

Create a custom Amazon Machine Image with WordPress pre-configured:

# User data script for WordPress setup
#!/bin/bash
yum update -y
yum install -y httpd php php-mysqlnd
systemctl start httpd
systemctl enable httpd

# Download and configure WordPress
cd /var/www/html
wget https://wordpress.org/latest.tar.gz
tar -xzf latest.tar.gz
mv wordpress/* .
rm -rf wordpress latest.tar.gz

# Configure wp-config.php with RDS connection
cat > wp-config.php << 'EOF'
> /etc/fstab
mount -a

→ WordPress RDS connection tutorial

5. Configure Auto Scaling Group

Set up automatic scaling based on traffic patterns:

# Create launch template
aws ec2 create-launch-template \
    --launch-template-name wordpress-template \
    --launch-template-data '{
        "ImageId": "ami-xxxxxxxxx",
        "InstanceType": "t3.micro",
        "SecurityGroupIds": ["sg-xxxxxxxxx"],
        "IamInstanceProfile": {"Name": "wordpress-role"}
    }'

# Create auto scaling group
aws autoscaling create-auto-scaling-group \
    --auto-scaling-group-name wordpress-asg \
    --launch-template LaunchTemplateName=wordpress-template,Version=1 \
    --min-size 2 \
    --max-size 6 \
    --desired-capacity 2 \
    --vpc-zone-identifier "subnet-xxxxxxxxx,subnet-yyyyyyyyy"

→ Auto Scaling Group configuration guide

6. Configure Application Load Balancer

Set up load balancing and health checks:

# Create Application Load Balancer
aws elbv2 create-load-balancer \
    --name wordpress-alb \
    --subnets subnet-xxxxxxxxx subnet-yyyyyyyyy \
    --security-groups sg-xxxxxxxxx

# Attach ASG to load balancer
aws autoscaling attach-load-balancer-target-groups \
    --auto-scaling-group-name wordpress-asg \
    --target-group-arns arn:aws:elasticloadbalancing:us-east-1:123456789012:targetgroup/wordpress-tg/xxxxxxxxx

→ Load balancer integration guide

⚠️ Configuration Tip: For detailed step-by-step instructions with Elastic Beanstalk alternative, reference AWS’s official WordPress tutorial. This approach automates much of the infrastructure setup.

Cost Analysis and Optimization

Understanding the cost structure helps optimize your infrastructure spending. This breakdown assumes 1GB monthly data transfer, two t3.micro instances, 1GB database storage, and 1GB EFS storage.

Monthly Cost Breakdown

AWS ServiceConfigurationMonthly Cost
EC2 Instances2x t3.micro instances$7.62
Application Load BalancerStandard ALB with health checks$18.82
RDS MySQLAurora MySQL Compatible, 1GB storage$9.09
Amazon EFS1GB shared file storage$0.30

Total Monthly Cost: $35.83

Cost Optimization Strategies

  • AWS Free Tier: New accounts can save approximately $20/month during the first year
  • Reserved Instances: Commit to 1-3 year terms for up to 60% savings on EC2 costs
  • Spot Instances: Use for development environments to reduce costs by up to 90%
  • CloudWatch Monitoring: Set up billing alerts and automatically scale down during low traffic periods

💰 Cost Calculator: Use AWS Pricing Calculator to estimate costs for your specific usage patterns. Note: EFS pricing is available separately at AWS EFS Pricing.

Frequently Asked Questions

Find answers to common questions

For a basic setup with two t3.micro instances, you're looking at around $36/month: $7.62 for EC2 instances, $18.82 for the Application Load Balancer, $9.09 for RDS MySQL, and $0.30 for EFS storage. The ALB is your biggest single cost. New AWS accounts can save about $20/month with the Free Tier during the first year. Want cheaper? Run a single instance without autoscaling for $17/month, but accept the 11 hours of annual downtime that comes with 99.99% uptime. Autoscaling costs more but eliminates downtime during traffic spikes and server failures.

Use AWS Elastic Beanstalk's WordPress template—it automates most of the infrastructure setup including the load balancer, auto scaling group, and RDS database. You'll still need to configure EFS for shared storage and CloudFront for caching, but Beanstalk handles the complex parts. The tradeoff? Less control over individual components and slightly higher costs due to additional managed service fees. For production sites, take the time to configure it manually using the step-by-step approach in the article—you'll understand your infrastructure better and have more optimization options.

Both work, but they serve different use cases. EFS ($0.30/GB/month) acts like a shared drive that all your WordPress instances can access simultaneously—no plugin required, works exactly like local storage. S3 is cheaper for storage but requires a WordPress plugin (like WP Offload Media) to handle file uploads and serving. S3 is better for media-heavy sites with lots of images and videos because you pay less for storage and can serve files directly from S3/CloudFront without hitting your EC2 instances. For sites with mostly text content and some images, EFS is simpler to set up and maintain.

You can't just update one instance—you need to update the AMI and redeploy. The process: launch a single instance from your current AMI, update WordPress core and plugins, test thoroughly, create a new AMI from the updated instance, update your launch template to use the new AMI, and then gradually replace instances in your auto scaling group. The wp-content folder on EFS updates automatically since it's shared, but core files require a new AMI. This is why separating your content from your code is critical—it's the only part of your infrastructure that needs this manual process.

CPU utilization is the standard choice: scale out when average CPU hits 70% for 5 minutes, scale in when it drops below 30% for 10 minutes. But request count per target can be more reliable for WordPress since a traffic spike might not immediately max out CPU. Try 1000 requests per instance as a starting point and adjust based on your instance size and page complexity. Avoid scaling on memory unless you have specific issues—WordPress is more CPU-bound than memory-bound. Always set a minimum of 2 instances for high availability and a maximum that won't bankrupt you during a DDoS attack.

If your site gets consistent traffic without major spikes and 11 hours of annual downtime is acceptable, stick with a single instance—it's half the cost and way simpler. You need autoscaling if: your traffic is unpredictable with major spikes (Black Friday sales, viral content), downtime costs you money (e-commerce, SaaS), you need true high availability with automatic failover, or you've already maxed out a single large instance. Don't use autoscaling for 'just in case' scenarios—vertical scaling (bigger server) is simpler and cheaper until you prove you need horizontal scaling. The complexity and cost of autoscaling only makes sense when the business impact of downtime or slow performance justifies it.

Secure Your AWS Environment

Expert AWS security, compliance, and architecture consulting for growing businesses.