This series will help you with setting up Dockerized WordPress website on you local machine and fully automate the deployment process to Amazon Web Services.
The website will be ready for heavy traffic. To achieve this, I have created the following topics:
- WordPress on AWS, the challenges
- Dockerize WordPress with themes, plugins and common configuration
- Prepare AWS Security Groups for WordPress project
- Create IAM (User, Roles and Policies)
- Create MYSQL database using AWS RDS
- Create AWS EFS (Elastic File System) Plugin storage for WordPress behind Load Balancer
- Build and Push wordpress project to AWS ECR
- Create Load Balancer for WordPress website
- Create Task Definition for WordPress Docker Project
- Putting all things together using AWS Task Definition
- AWS Codepipeline
- Speed up your WordPress website for better SEO
I know it sounds a bit harsh saying that WordPress is not civilized enough for AWS but hear me out !
I have been working with modern frameworks such as Rails, Laravel and reactJS for some time now. All these frameworks have evolved so much overtime and ready for multi environments, CI/CD, Load balancers and the list goes on.
Our main product is built on Rails and its fully automated with AWS CI/CD and other automation. Sound great isn’t it?
We recently decided to separate our behind the paywall application and content from each other. In simple words, our complex application (built in Rails) will stay as it is. On the other hand, for content such as blog, marketing pages and few other things such as recipes will be on WordPress.
I will take you through the journey of the whole process and lessons I have learnt during this process of making WordPress shine on AWS with CI/CD, Load balancers and how much WordPress is not ready for that transition by default.
So Let’s make WordPress up its game !
Let’s begin with the challenges I have faced and then you can make the call if these are the right series of tutorials for you or not.
1 | Load balancer and bloody plugins
We all love the fact that on WordPress, we can install plugins without a deployment. Here’s the challenge with this approach, if your WordPress website is behind a Load balancer and there are multiple instances running. You will be installing the plugin only on the instance you are connected to. It will crash for the users who are connected to other instances.
One simpler solution is to deploy the WordPress website again with the plugin included. It takes away the freedom of installing or un-installing a plugin without a redeployment.
AWS Elastic File System (EFS) is our answer, we will simple mount the plugin directory of WordPress instances to our EFS. Please take a look at the diagram below:
AWS EFS is not just highly available, its IO operations are blazing fast. Don’t worry it won’t slow your website down at all.
2 | Centralized MYSQL Database
Most of the people are probably using AWS RDS already with their WordPress websites. We will be using the same too. Just a centralized database for WordPress website behind Load Balancer.
3 | De-couple variables stored in Database and DO NOT configure the Apache or Ngnix every time
Simple as it sounds, variables such as SITE_URL will not be stored in MYSQL database. You know we always have to configure Apache or Ngninx for the wordpress websites.
A lot of people create/use Amazon Machine Images (AMI) for that purpose. the only problem with using AMI is configuration changes. You will have to create a new AMI on every change you make. Damn what a waste of time.
We will have a boiler plate WordPress Docker template which can kick start any WordPress website in minutes without configuring Apache, Ngnix and other settings.
4 | Website performance and SEO challenges
There are so many plugins available for WordPress website performance boost. I will share the ones I have used and what have worked for us in the end.
5 | AWS Elastic Container Service
Finally, How to use Amazon Elastic Container Service which includes the following:
- Amazon Elastic Container Registry (ECR)
- Our Docker build repository that contains our most recent Dockerized WordPress project with all the server configurations
- Amazon ECS Task Definitions
- This is where we use our Docker build and put all the variables for our WordPress website; Remember we’re not keeping our website variables in the database.
- Amazon ECS Clusters
- This is where it creates the EC2 instances of your WordPress website using the ECS Task Definitions.
I am loving this blog post man!!! Honestly been racking my brains about enterprise scale wordpress deployments on AWS.
This is serious life-saver!!!
One question though – is there any ETA on the last Codepipeline section of the blog?
Thanks for liking the blog mate. I will try to move my lazy ass within two weeks. I have learned few more things on wordpress optimization which I will also share soon.
This whole series is really fantastic.
I do have a question for you, if you don’t mind, how would you go about getting wordpress running, but not have to go through the installer? the wp_config.php file doesn’t exist in /usr/src/wordpress so everytime I access the site it starts the installer. It would also seem that any new tasks that are started would not have this file as well. Should it be copied into the image when it is built? And how do you get the correct values in it for the production db, user, host etc.?
Mate, your posts are stunning. Great resource on word press setup on AWS.
Any plans for codepipeline? Anxiously waiting for it.
Thanks for liking my content.
I will try my best to post it soon.
Hai Salmansohail,
I have followed your blog and done wordpress setup on AWS. Whenever the ECS Task is restarted the images present in wp-content/uploads folder are got deleted. How to make them persistent. Please help me out in this scenario
The best way is to use s3 bucket for images. storing pictures inside the container is a bad idea. Try WP offload media lite plugin.
It is very helpful article… this blog helps me a lot while configuring in my tenant… great blog Sir
conceptual, amazing…well writing Sir, hopefull this article helps lots of students and professional while learning AWS.