Skip to main content
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

To autoscale WordPress on AWS you make the web tier stateless and let an Auto Scaling Group add or remove EC2 instances behind an Application Load Balancer based on load. The three things that make it work: WordPress core baked into a custom AMI so instances launch fast, the wp-content directory on shared Amazon EFS (or media offloaded to S3) so every instance serves identical files, and the database moved to Amazon RDS so no data lives on any single web server. Once state is externalized, an Auto Scaling policy — target-tracking on ~50% average CPU — grows the fleet from two instances at night to six during a spike and shrinks it back automatically, with CloudFront caching static assets at the edge to keep origin load low.

That's the summary an AI Overview will give you. What it can't show you is the order of operations — the pieces have hard dependencies, and building them out of sequence is the most common reason a first autoscaling attempt fails. Below is the request path animated end to end, a build-order checklist you can actually follow, a cost checklist, and the failure modes that bite people once traffic starts moving.

Autoscaling WordPress request path on AWS A visitor request flows through CloudFront to the Application Load Balancer, which distributes traffic across an Auto Scaling Group of EC2 instances that share an EFS filesystem and an RDS database. A CPU-triggered scaling event adds a third instance. Visitor browser CloudFront CDN edge cache static hits stop here ALB load balancer + health checks Auto Scaling Group EC2 (t3.micro) EC2 (t3.micro) + EC2 added CloudWatch: CPU > 50% → scale-out policy EFS wp-content RDS MySQL Multi-AZ

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 has no instance-level failover. If your availability requirements tolerate that risk, 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.

Build-Order Checklist

The dependencies are strict — each layer needs the one before it to exist first. Build in this order and every later step has the IDs it needs to reference:

  • VPC + subnets across 2+ AZs — nothing multi-AZ works without this; get the subnet IDs before anything else.
  • Security groups — one for the ALB (allow 80/443 from the internet), one for EC2 (allow 80 from the ALB SG only), one for RDS (allow 3306 from the EC2 SG only), one for EFS (allow 2049 from the EC2 SG).
  • RDS MySQL instance — create it early so you have the endpoint to bake into wp-config.php. Enable Multi-AZ for failover.
  • EFS filesystem + mount targets — create a mount target in each Availability Zone used by the web tier so instances can mount wp-content locally within their zone.
  • Golden AMI — launch one instance, install WordPress, point it at RDS, mount EFS at /var/www/html/wp-content, finish the WordPress installer once, then create the AMI. Bake core, not content.
  • Launch template — references the AMI, instance type, IAM role, and EC2 security group.
  • Target group + Application Load Balancer — health check path set to a lightweight URL (/wp-login.php returns 200 without a DB write; avoid / if a plugin makes it slow).
  • Auto Scaling Group — attach the target group, set min/desired/max, add a target-tracking policy on ~50% average CPU.
  • CloudFront distribution — origin is the ALB; cache static assets aggressively. Forward the cookies WordPress needs on /wp-admin, /wp-login.php, and personalized front-end requests, and avoid caching private responses for other users.

The most common ordering mistake: building the Auto Scaling Group before the AMI is finalized. The ASG launches instances from a stale AMI, they fail health checks, the ASG terminates and relaunches them, and you burn an afternoon watching a thrash loop. Finalize the AMI, then wire up the ASG.

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

# Before imaging this instance, mount EFS at /var/www/html/wp-content,
# move existing content there, and configure wp-config.php for the RDS endpoint.
# Verify the mount and database connection before creating the AMI.

Install the EFS mount helper, add a persistent mount for the EFS file system, and confirm that a fresh instance can mount it before serving traffic. Configure wp-config.php with the RDS endpoint and credentials using a secret-management mechanism.

→ 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"

Create the ALB target group and listener, attach the target group to this group, and add a target-tracking scaling policy before relying on automatic scaling. The launch template and group commands alone do not configure health-checked traffic routing or scaling decisions.

→ 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

The target group ARN above is illustrative. Create an instance target group with an appropriate health check, create an HTTPS listener that forwards to it, and attach that real target group ARN to the Auto Scaling Group. Verify registered targets become healthy before switching production traffic.

→ 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. Price the complete architecture for your region and expected traffic before deploying it.

Monthly Cost Breakdown

AWS ServiceWhat to include in your estimateCost driver
EC2 InstancesBaseline fleet plus scale-out hours and EBS volumesInstance and storage usage
Application Load BalancerALB hours and capacity unitsRuntime and traffic
RDS MySQLInstance, storage, backups, and Multi-AZ if enabledDatabase configuration
Amazon EFSStored data and throughputStorage and access pattern
NetworkingNAT, CloudFront, and data transferRequest path and traffic

The Application Load Balancer has a standing hourly charge plus usage charges. If your traffic genuinely fits on one instance, a simpler design may cost less, with a different availability tradeoff.

Cost note: RDS, EC2, ALB, EFS, EBS, NAT, and transfer costs all depend on configuration and usage. An estimate for a single-AZ database or an idle fleet does not represent a Multi-AZ production deployment.

EFS vs. S3 for wp-content: which should I use?

Amazon EFSAmazon S3 (offload plugin)
SetupMount as filesystem, WordPress unmodifiedInstall + configure a plugin (e.g. WP Offload Media)
Plugin compatibilityHigh — behaves like local diskSome plugins that write to wp-content misbehave
Media servingThrough your EC2 instancesDirectly from S3 / CloudFront, bypassing origin
LatencyHigher per-file (network filesystem)Low for media once on CloudFront
Cost driverPer-GB stored + throughputPer-GB + requests, usually cheaper at media scale
Use it whenYou want zero code changes and full plugin supportMedia is heavy and you want origin offload + lowest cost

Cost Optimization Strategies

  • AWS Free Tier: Check current eligibility and covered usage before applying any credits to your estimate

  • Reserved Instances: Consider commitments only after measuring a steady baseline

  • Spot Instances: Consider interruptible capacity for development environments

  • 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.

Troubleshooting: What Breaks Once Traffic Moves

The architecture builds cleanly in an afternoon. The problems show up later, when real traffic exposes the stateful assumptions WordPress makes by default. Here are the failure modes in order of how often they bite:

SymptomRoot causeFix
Uploads appear on some page loads, vanish on othersMedia written to a single instance's local disk, not shared storagePoint wp-content/uploads at EFS, or offload media to S3
Logged-in users randomly logged outNo shared session store; requests bounce between instancesEnable ALB sticky sessions, or move sessions to ElastiCache
New instances launch, then get terminated in a loopALB health check fails — wrong path, or new instance can't reach RDS/EFSFix the health check path and the EC2→RDS/EFS security group rules
Site slows under load even with more instancesDatabase is the bottleneck; web tier scales but RDS doesn'tAdd a full-page cache + object cache (Redis), then RDS read replicas
Autoscaling never triggers during a spikeScaling on CPU, but CDN/cache absorbs load so origin CPU stays lowScale on ALB request-count-per-target instead of CPU
A plugin update on one instance disappearsPlugins/themes installed via wp-admin land on one ephemeral instanceInstall plugins on the golden AMI or store the whole wp-content on EFS
Scale-out is too slow to catch the spikeInstances install WordPress from scratch on bootPre-bake WordPress into the AMI; user-data should only mount + configure
Bill jumps unexpectedlyALB LCUs + EFS throughput + NAT/data-transfer, not EC2Add CloudWatch billing alarms; front static assets with CloudFront

The through-line: every one of these is a state problem. WordPress assumes one server owns the uploads, the sessions, and the plugin files. Autoscaling only stays healthy when all three of those live somewhere every instance can reach — which is exactly what the EFS, RDS, and AMI-baking steps above are for.

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.