WordPress on Amazon AWS

So you’ve heard you need a need a fast website, either from Google’s PageSpeed test or some other article on the topic. Maybe you’d like your readers to not get bored while the page is loading. Or you know that Google favors fast websites when returning search results. You may also want a website that ‘scales’ to higher levels of visitor traffic. That is, a WordPress website that will load quickly whether you have 1 customer browsing or 1000.
Why Amazon AWS is a Good Fit
The Amazon AWS service is basically a growing list of pre-made building blocks that you can use to build your website. These components are all built using Amazon’s age-old policy of seeking price-leader status in any industry they compete in. One concept Amazon has promoted across their entire line-up is the “pay as you go” approach. You don’t have to provision or reserve more service resources than you need. And any time you stop using a service, you stop paying for it.
Because of this approach you can pay for a tiny amount of resources at the beginning of your business venture without significant capital expense. But if your content goes mainstream and you need to add a large amount of IT capacity then you can quickly do this by adding servers only for the time you need them. This is very different from the “provisioned resources” approach used in the past.
Introducing the Amazon AWS EC2 Service
Amazon EC2 is the equivalent of a physical computer except there’s no large capital expense incurred while acquiring this equipment. Also when you no longer need it there’s no hassle getting rid of it. Like every other computer it has a certain amount of memory, it has drive space, it has a fast internet connection. When you sign up for the EC2 service, you basically get your own “virtual” computer for your WordPress Website. This “virtual server” is called an “instance”. That new server “instance” is all yours and it’s up to you and your team to take good care of it.
EC2 is actually the main service you will use in hosting your WordPress website with Amazon. EC2 provides the actual computer or server that will be running your website, so to speak. Each “instance” allows you to run an unlimited number of website domains. So you can run “example.com”, “shop.example.com”, “blog.example.com”, “othersite.com”, “blog.othersite.com”, etc. all while paying for a single instance.
A common misconception is that Amazon EC2 instances increase their resource usage automatically when needed. That is not the case right now. It is not possible to ‘grow’ a server’s CPU or Memory resources after it’s been created. But WordPress can be configured to run over multiple servers or Amazon EC2 instances. The process of running a single site over multiple instances is normally called “scaling”. There are lots of website scaling techniques and choosing the right one for your website is something an experienced Amazon System Integrator can help you with.
Your Amazon EC2 server instance can be created in many parts of the world. Amazon has locations on the US East or West coast, in Ireland, Japan, Singapore, Brazil, and the list is increasing. As a general rule, your website visitors get your pages loaded quicker if your server instance is geographically closer to them. So if your users are coming from China, it makes a lot of sense to start at least some of your instances in Singapore or Japan.
Amazon S3
This is a service that allows you to store as much data as you need on a pay-what-what-you-use basis. You can use S3 storage to store all your WordPress images for instance, or if you have logs of large files available for download on your website.
With Amazon Services, you’re responsible for your own website backups. And some backup applications allow saving backups to Amazon S3 storage or “buckets” as they’re ofen called. So now if your server gets hacked or corrupted, you can get all your important files from S3 storage. This is part of the Amazon AWS “shared-responsibility” model.
There are desktop programs like http://s3browser.com/ and http://www.expandrive.com/ that allow you to connect your local desktop computer directly to Amazon S3 storage. This allows you to have a nice unlimited connected drive or folder on your laptop.
With Amazon S3 there is no guessing how much space to purchase before your WordPress site needs it. That translates into huge cost savings as you never pay for excess storage capacity.
Amazon CloudFront
Remember that your website visitors get quicker page load times when your server instance is geographically close to them. So if your server instance is hosted in the state of Virginia, USA, then your Florida, Georgia, and even New York visitors are all going to get better response times than your California or Seattle visitors. But if your server were in Oregon or California, then the reverse would be true. This is also true on a global scale. A “CDN” or “Content Delivery Network” allows you upload all your files to a single service that in turn sends your files to your visitors based on where they are coming from. So basically, if you put all your WordPress images in a CDN then a user from Colombia may get these files returned from the Brazil servers if these are closest. A user from Hong Kong may get the Singapore servers, etc. The CDN network takes the guess work out of figuring out how to get the closest server to your visitor. And it does so for every visitor.
CloudFront is Amazon’s Content Delivery Network of servers. Using Amazon CloudFront, your website will return files to your visitors based on the closest server to their geographic location. Without CloudFront, your WordPress website would be returning files to all your users based on your servers single location.
Using a CDN is one of the best early performance optimizations that a WordPress site owner can do. We use W3 Total Cache’s CDN integration capabilities to update and serve files from Amazon Cloudfront.
Amazon SES
Email is a very important method of interacting with your visitors. Busy websites often send out thousands of “transactional” email messages everyday. It’s important to know that by default Amazon AWS implement very strict email sending rules on servers. This is to deter spammers from using AWS services. Not only that, but many email server administrators block emails coming from Amazon EC2 servers due to the risk of it being spam.
There is one way to side-step the server email sending limits. You can use Amazon AWS Simple Email Service to send out all your emails. Amazon even throws in a generous 2000 emails per day quota gratis. Using Amazon SES means that your email messages are more likely to get to your website visitors.
PHP APC
One of the nice things about being on a Cloud Server like Amazon EC2 is that you can install just about anything you need to on there. One of the first extensions I add to WordPress on any server we optimize is “PHP APC”. WordPress is created using the “PHP” programming language and so when any WordPress page is accessed, that page is quickly converted into a computer readable form, then executed, and finally the results are returned to the user. PHP APC is an optional add-on that we can install very quickly. It improves on the page loading process by keeping the converted computer readable form of your pages around long after the first user has viewed your page. Hence every other user skips that CPU-intensive PHP code “conversion” step. The result is both slightly faster page loads for your readers and the ability to service more viewers on a single server instance.
Amazon RDS
Every WordPress site requires a MySQL database. MySQL is a free database server program. Normally that MySQL program is either run on your instance or run by your hosting provider. Either way, you get a database for WordPress to store all your website information. Amazon provides a third way.
Amazon allows you to get a database on a ‘pay-what-you-use’ model, just as with all their other services. With Amazon RDS, you let Amazon deal with running MySQL. They handle keeping the server running, upgrades, backups, replication, server tuning, etc. etc. The headache is all theirs. You simply pay for your database by the hour and based on how much space you use. Note that Amazon AWS has another database service called ‘DynamoDB’ that is a great service but is not compatible with WordPress since WordPress requires MySQL.
I find that ‘database-as-a-service’ works for some clients and doesn’t work for others. An efficient Database Administrator can keep a busy MySQL server up and running optimally with very little effort. And RDS hourly rates over the usual Amazon EC2 fees can get quite a bit expensive. I’d suggest using the AWS calculator as well as some testing on load scenarios to come up with a good estimate before totally committing to Amazon RDS.
Choice of Webserver
The “web server” software you use is normally of little importance to most WordPress site owners. But as you focus on performance and “scalability”, you’ll find that a lot of issues that were not a concern in the past become more of a concern now. Your web server software is simply the software your viewers directly interact with. The key take-away for this article regarding webserver software is that, first there are two common types on Amazon Linux, “Apache Web Server” and “NGinx Web Server”. Also, one web server maybe more efficient than the other depending on your websites unique circumstance.
I’ve worked with Apache Web Server for almost 15 years now and it’s been a really good piece of software. But maybe it’s because of it’s age, but there are a lot of “system design decisions” that should be chosen by default that are not with Apache. NGinx, on the other hand, is the new kid on the block and is designed from the ground up to be incredibly fast. The result is that NGinx works will for most WordPress installs I work on these days. It’s quick, stable and gracefully handles an incredible amount of traffic without hogging resources.
Misc. Services
Memcached is a program that runs on the instance, basically saving your WordPress data in memory so it doesn’t have to access the slower disk or database each time a viewer accesses your website. It’s an invaluable tool for high performance WordPress websites but not something you’ll get on most $5/month shared hosting plans.
W3 Total Cache
This is the WordPress plugin that makes it all happen. W3 Total Cache is a very impressive WordPress plugin. It provides a variety of performance related optimizations that help WordPress sites like yours reach their full performance potential.
This cache has quite a few bells and whistles that may not make sense at first but when correctly configured will make a big difference to your website. For example W3 Total Cache can be configured to make WordPress utilize Memcached service. Without W3 Total Cache plugin, WordPress would not be able to utilize Memcached or automatically update Amazon CloudFront CDN.
Running Multiple Servers for WordPress Performance
This right here can be a series of articles all by itself. But the short version is that by separating the various services or programs your website needs on different Amazon EC2 Server instances you site can grow to support much more traffic. Smaller WordPress sites run all the programs they need on one server instance. This lowers the website cost because you pay Amazon per instance per hour. But as your blog grows larger and gets more traffic each of those services will need more resources and eventually outgrowing that one server instance.
The first task I like to do in a multi-instance WordPress configuration is to separate the database so it runs on its own server instance. That way I can configure the operating system, disk, memory usage on that separate database instance to suit MySQL perfectly and improving performance greatly. An alternative to setting up and maintaining a separate MySQL database is to use Amazon’s RDS service. This is basically a “database-as-a-service” feature of the AWS platform.
Another type of server instance that helps WordPress quite a bit is called a “Caching Server”. The software on these servers access your website much like a regular user with a browser does and keeps the results they found from your web pages. You then configure your domain’s “DNS” to point to these Caching servers, having them respond for your website instead of the instance that actually runs WordPress. The result is that your site appears to be incredibly fast to your visitors.
If you have any questions please feel free to contact us today about your WordPress website on Amazon AWS.