Create a Scalable Wordpress Hosting on AWS
Create a Scalable Wordpress Hosting on AWS
Check out how you can increase the availability and scalability of your website by hosting on AWS and its associated services.
Join the DZone community and get the full member experience.Join For Free
Learn how to migrate and modernize stateless applications and run them in a Kubernetes cluster.
Do you own or manage a Wordpress site? Is it complex with a lot of traffic? I’m going to show you the ideal architecture to host a highly-available and scalable Wordpress site on AWS.
This blog is intended to show a distributed architecture in AWS for Wordpress CMS Websites. You will be able to identify the different layers of services needed to run a high traffic Wordpress.
Concepts of a High Scalable and Available Environment
High-Availability: This means that a system can operate without any service disruption or interruption for a long time as well as for a system that has redundant components. (In our case the redundant Infrastructure will be our high availability).
Distributed Services — Loose Coupling: The art of distributing different components of a system in the same network. We will be doing this to leverage the load of any resource and have dedicated hosts for a service.
Scalability: A system’s ability to monitor the user demand and automatically increase or decrease resources. This scalability will be provided by the following AWS Resources: AWS ELB, AWS EC2, AWS S3, AWS RDS.
One essential part of innovation is to always to stay up-to-date and implement the best technology available.
“Technology is like a fish. The longer it stays on the shelf, the less desirable it becomes.” — Andrew Heller
First Things First
If you are planning to follow this blog, it is because you are looking to migrate to Amazon Web Services or you already have an environment or some resources allocated there.
If you are already on AWS, we have also compiled a very concise checklist which you can obtain here.
AWS Services Explained
- Route53: This service will help us to manage all the upcoming requests (traffic) that our domain will have. AWS Route53 will also be the DNS Manager, so here we will point our domain registrar to be the manager, and once it has been migrated here, we can add the A records, Cnames, or TXT records and many other more.
- AWS VPC: The AWS VPC is a service that allows us to have a private network in which we will allocate our cloud computing resources, meaning nobody has access to it but us ourselves.
- AWS Private Subnet: The private subnet is the subnet in which we are going to deploy the resources we don’t want outsiders to have access to. In this case, our database will be only accessible by the application.
- AWS Public Subnet: The public subnet is the subnet in which we are going to deploy the resources we want to make public — like the server for our website.
- AWS S3: Amazon Simple Storage Service will be our content storage solution. Here our Wordpress installation(s) will have the content available whenever it scales up or off.
- AWS CloudFront: CloudFront combined with S3 will help us to spread the content faster to the end users. This way our Wordpress multimedia content will be spread all over AWS CDN Network (Edge Locations) which will be used from our application to reduce the latency. Users will be served by the closest edge location available. So faster content equals a faster site.
- AWS Load Balancer: Here is the tricky part. The AWS ELB will allow us to distribute the traffic load between our instances available or in use depending on how the auto scaling is set.
- AWS EC2: Also called instances, or “VM’s”, this is the service on AWS for acquiring computing power. AWS EC2 will allow us to host our Wordpress site and files we need.
- AWS Autoscaling: The magic — here it is! This will be the solution for our highly-available and scalable Wordpress site. AWS Autoscaling will take care of always having a minimum quantity of instances available for the public and in case something goes wrong, it will replace the instance with a healthy one so our site will always be available. Autoscaling will also benefit our WordPress by creating instances based on the traffic demand and will help us to save costs while the traffic is low.
- AWS RDS & Multi A-Z: RDS will be the service in which we will host our Wordpress database. The service is completely free and fully managed by AWS. So that gives AWS an advantage since we won’t need to worry about the database management anymore. Also, a useful feature is that RDS instances can have replication between them that adds even more scalability. Another feature which will provide us high availability is enabling the Multi-Availability Zone (Multi A-Z) feature. Keep an eye on this since the price will is double for the RDS.
- AWS Cloudwatch: AWS Cloudwatch will be our trusted supervisor. Cloudwatch will be in charge of monitoring all the resources in our AWS account. It will keep an eye on the metrics that are predefined or as default by AWS resources, such as CPU usage, memory usage, Disk IO, and networking.
Did I Forget About EFS?
Nope, In my experience, EFS has not been a huge help when it comes to sharing the Wordpress files only. However, you can try using EFS to replicate content in a much faster and easier way.
If you want to learn more about the technologies and the approach that should be taken to create this kind of environments, take a look at this post.
How AWS Influences Site Traffic
Here is how your visitors get to your site — once they hit your domain on their browser their request will pass to the Internet, route it to your DNS manager, and the DNS manager (Route53) will solve the request to the specified server, the web server then will serve the application.
What will happen when your traffic increases? Well, here is an example:
Let's say that you have set the autoscaling, with a minimum number of instances of 1 and a maximum number of 3. Based on different metrics, your environment will be able to scale out depending on the load it receives.
In the image above, we can see that depending on the Aggregate Load, the environment continues to satisfy the demand by creating more instances as it grows and the same happens the other way.
What does this mean? It means a lot when you are calculating the TCO of your cloud environment. Also means that you won’t run out of memory or other resources, but that you will have a more available system.
And you might be wondering, "What is going to happen to my AWS Resources?" Well, this is it:
Simple: more demand/traffic, more servers to meet it.
“Everything must be made as simple as possible. But not simpler.”
― Albert Einstein
Server Caching/Wordpress Caching
Server-side caching or Wordpress-side caching with a plugin or embedded in a host. Whenever someone visits a part of the website, the homepage, for example, the request is passed to the database to retrieve the homepage information. What caching does is it creates a temporary file (I say temporary because you can specify the expiration) so when your request comes, it will check for the files it generates instead of processing the request to the database.
This way we can serve faster pages/content to our end users and reduce the database consumption.
If you yet don’t have a caching system implemented, make sure you do from now on as it speeds up your website dramatically.
CDN: Content Delivery Network
In a few words, the CDN is the network of servers or services in which your content will be hosted. This network will be used to transfer the content to all the visitors. Using a CDN will help you to spread your content around the world faster than having it hosted on your server.
Based on the CPU and Memory Metrics, our stack will be able to scale up or scale in as desired. This way our response time will always be the same between all the servers and what matters is that our traffic doesn’t get to any instance having an overload due to CPU or memory (these are the annoying 500’s errors).
On AWS we have different instance types that we can use depending on the workload we have. We always recommend choosing the right instance type.
Definitely using the correct instance type for our Wordpress will help. As well by selecting the number of resources for it to run.
And there you have it — you now know how your site could support millions of pageviews with a distributed system.
Here Are Some Other Things Worth Mentioning…
Backup and Disaster Recovery
It is essential to have a backup strategy as well as a disaster recovery solution in case something happens to our Wordpress installation or our environment. Luckily, AWS offers a lot of redundancy between all its services, so that’s a plus for AWS!
There are different ways in which we can protect our application and user’s data:
- Wordpress Plugins to Backup the Site. (S3)
- Disaster Recovery for Infrastructure (Physical).
- Backup for Users Data (DB — RDS).
- Backup for Application Code.
Amazon Web Services already provides different backup solutions for all its services, so we will be able to create backups for the RDS with one click and perform the configurations for backups with EC2.
- To increase the performance, use a database, query, and page caching plugin.
- Increase the RDS performance with a dedicated Aurora RDS.
- Use S3 and CloudFront to deliver the content faster.
- Enable Alarms on AWS Cloudwatch.
- Enable the Billing Alarm to avoid unwanted charges for usage.
- Use Reserved Instances! If you are going to stay in AWS for a long time reserve, it will save you up to 30%.
- Use a Version control system to track your changes and deploy to the instances.
In this article, I described what I consider an ideal architecture for a high performance/high traffic Wordpress site. As you can see, Amazon provides us with all the tools and technologies to do it, but sometimes it results to be challenging.
As always if you think I missed anything, please post it in the comments!
If you would like to get more techie blogs, subscribe to our Newsletter.
Published at DZone with permission of Guillermo Velez . See the original article here.
Opinions expressed by DZone contributors are their own.