šŸ‘‰ AWS Debug Games (Beta) - Prove your AWS expertise by solving tricky challenges.

šŸ‘‰ AWS Debug Games - Prove your AWS expertise.

WordPress on AWS: you are holding it wrong

Andreas Wittig ā€“ 03 Nov 2015

WordPress is a very popular blogging software. You can run the PHP application together with a MySQL database on an EC2 instance (virtual machine) easily. But if you are following the official tutorial to setup your blogging environment on AWS you are missing two important advantages:

  • High Availability: a single EC2 instance is not highly available. A failing host system or datacenter will cause an outage of your virtual machine and therefore of your WordPress blog.
  • Scalability: a single EC2 instance is not scalable. If one of your blog posts gets attention from Hacker News or another social media source, you are not able to serve all the incoming requests properly.

The following figure shows the services that are needed to build a highly available and scalable WordPress environment on AWS for approximately 75.00 USD per month.

WordPress: highly available and scalable

The following sections will explain the concepts and services used in detail. You will find a template that you can use to spin up the necessary resources on AWS within minutes at the end of this article.

Stateless server

A stateless server is the pre-requisite for building a highly available and scalable infrastructure on AWS. A stateless server does not store any data expect of temporary data like caches.

By default WordPress is storing data in two different ways:

  • MySQL database: articles, comments, users and parts of the configuration are stored in a MySQL database.
  • File system: media files uploaded by the authors are stored on the file system.

If the MySQL database is running on the same EC2 instance as the WordPress application itself, the server is not stateless. Same is true for the media files stored on the file system.

Why is this a problem? Because if the virtual machine becomes unavailable, the data will be unavailable, too. And if you need to add another EC2 instance to handle more traffic all the data will be missing on the additional server.

A stateless server is the easiest way to build a highly available and scalable WordPress environment. You can achieve a stateless server by outsourcing the state of your virtual machine as described in the following sections.

Looking for a new challenge?


    Cloud Operations Lead

    DEMICON • AWS Advanced Consulting Partner • Remote (Europe)
    service-delivery-management hiring devops platform

RDS: managed MySQL database

WordPress uses a MySQL database to store articles, comments, users and configuration. You can use RDS (Relational Database Service) to spin up a managed MySQL database on AWS. RDS supports master-standby setups (called Multi-AZ) offering an easy way to achieve high availability for MySQL databases.

S3: media file storage

By default, WordPress uses the file system to store media files (images, videos, ā€¦) on the disks attached to the virtual machine. Unfortunately, this is a show stopper if you want to build a stateless server. You can use a plugin for WordPress to store media files on S3. Amazon S3 is a highly available and scalable object store offered by AWS and can be used to outsource media files.

Outsourcing the state to RDS and S3 allows you to achieve the concept of a stateless server for your web servers. The next challenge is to manage a dynamic number of virtual machines to serve the incoming HTTP requests.

ELB: synchronous decoupling

Scaling horizontally means adding more virtual machines to handle traffic peaks. To allow multiple servers to answer HTTP(S) requests in parallel you need to distribute the workload. A load balancer solves this problem for synchronous requests (e.g. HTTP requests). AWS offers a highly available and scalable load balancer: Elastic Load Balancer (ELB).

Auto Scaling based on usage

The big advantage of AWS and other public cloud providers is the possibility to add and remove capacity on demand. AWS offers a feature called Auto Scaling helping you to spin up and terminate virtual machines based on the current workload. For example, the number of EC2 instances can be increased if the CPU load reaches 75%.

Auto Scaling will also replace failed EC2 instances even if a whole datacenter (availability zone) fails.

CloudFormation template available

Sounds like a lot of work to create a highly available and scalable WordPress setup on AWS? Not if you are using the right tool for the job: AWS CloudFormation. Iā€™m offering a template that you can use to create the described WordPress setup automatically within minutes.

You will find the CloudFormation template to create a highly available and scalable WordPress setup on GitHub: widdix/aws-cf-templates.

Become a cloudonaut supporter

Andreas Wittig

Andreas Wittig ( Email Twitter LinkedIn Mastodon )

We launched the cloudonaut blog in 2015. Since then, we have published 365 articles, 67 podcast episodes, and 67 videos. It's all free and means a lot of work in our spare time. We enjoy sharing our AWS knowledge with you.

Please support us

Have you learned something new by reading, listening, or watching our content? With your help, we can spend enough time to keep publishing great content in the future. Learn more

Amount must be a multriply of 5. E.g, 5, 10, 15.

Thanks to Alan Leech, Alex DeBrie, Christopher Hipwell, e9e4e5f0faef, Jason Yorty, Jeff Finley, jhoadley, Johannes Konings, John Culkin, Jonathan Deamer, Juraj Martinka, Ken Snyder, Markus Ellers, Oriol Rodriguez, Ross Mohan, sam onaga, Satyendra Sharma, Simon Devlin, Todd Valentine, Victor Grenu, and all anonymous supporters for your help! We also want to thank all supporters who purchased a cloudonaut t-shirt.