👉 AWS Debug Games (Beta) - Prove your AWS expertise by solving tricky challenges.

👉 AWS Debug Games - Prove your AWS expertise.

WordPress on AWS: smooth and pain free

Andreas Wittig – 31 Oct 2016

I’m not a fan of WordPress, as it is neither cloud-ready nor serverless. That’s why this blog runs on CloudFront and S3 and is built by Hexo. But 25% of all websites are proudly published with WordPress. You will learn about the easiest way to run WordPress on AWS . Including fault tolerance and scalability.

The following figure shows the architecture of a fault tolerant and scalable WordPress environment on AWS.

WordPress on AWS

Read on to learn more!

The problem

WordPress is a PHP application using two different data storages: a MySQL database and files on disk. Storing files on disk is a problem if you want to make use of a fleet of EC2 instances to run WordPress in a fault tolerant and scalable fashion.

The following example and figure are illustrating the problem.

  1. Mary is uploading a new image for her blog post. The image file is stored on EC2 instance number 1.
  2. Mary is reading through her article. EC2 instance number 1 is answering her HTTP request to get the image.
  3. Bob is reading Mary’s article. EC2 instance number 2 is answering his HTTP request with a 404 Not Found error, as the image is stored only on EC2 instance number 1.

WordPress stateful server

Tricky, you need to find a way to either synchronize files between all EC2 instances or outsource the files to a managed service.

The solution, 1st try

I tried to solve the problem of running WordPress on AWS before. WordPress on AWS: you are holding it wrong describes the solution in detail.

To summarize it briefly:

  • Using a WordPress plugin to store user uploads like images on S3 instead of storing them on disk.
  • Disabling all other WordPress features that are writing files to disk: install and update plugins or themes, the auto-updater, and writing a .htaccess file.
  • Automating the process of installing WordPress with all of its plugins and themes during the boot process of each EC2 instance.

But not being able to install plugins and themes and to use the auto-updater is inconvenient.

The solution, 2nd try

The Elastic File System service (EFS) joined the AWS family in January 2016. EFS is a highly available and scalable network file system that you can connect to your EC2 instances by using the NFS protocol. The perfect place to outsource files.

Looking for a new challenge?


    Cloud Operations Lead

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

The following figure shows how each EC2 instance running WordPress is connecting to EFS to read and write files. You don’t need to distinguish between user uploads and files belonging to WordPress itself.

WordPress with EFS

The diagram was created with Cloudcraft - Visualize your cloud architecture like a pro.

As a network call is necessary every time your EC2 instances want to read a file from EFS, it is important to have file caching in place.

Especially for .php files, as WordPress needs to access a lot of .php files for each incoming request. Something you can solve with opcache quickly.

Caching static files is necessary as well. Because each visitor of your WordPress blog will need to load the same .css and .js files a CDN like CloudFront is a perfect fit.

The following figure shows the complete architecture of WordPress on AWS based on these services:

  • CloudFront: CDN for dynamic and static content
  • ELB (Elastic Load Balancer): load balancer forwarding requests to EC2 instances and terminating SSL
  • EC2 (Elastic Compute Cloud): virtual machines running the web servers
  • EFS (Elastic File System): storage for WordPress files (WordPress core, plugins, themes, and user uploads)
  • RDS (Relational Database Service): MySQL database

WordPress on AWS

The diagram was created with Cloudcraft - Visualize your cloud architecture like a pro.

The deployment

Do you want to run WordPress on AWS by using EFS as described above? I have created a CloudFormation template that you can use to create the needed cloud infrastructure within minutes including the following features:

  • Reliable: Fault tolerant and scalable due to multi-AZ usage
  • Secure: HTTPS only
  • Fast: CDN caching static content
  • Growing: scalable file storage for endless user uploads

Learn more about the CloudFormation template for running WordPress on AWS and launch your stack within minutes.

This blog post has been translated into German: WordPress reibungslos und schmerzfrei auf AWS betreiben.

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.