AWS Guides: Speed Up or Optimize WordPress in the Cloud

wordpresslogoHey guys, below is a tutorial on how to speed up your WordPress installation in the Cloud. This tutorial will cover an installation of WordPress on a Linux LAMP stack on a instance on the AWS Cloud inside Ec2.

First things first, depending on your instance size and specs you will need to run some calculations on how much your server can actually take. Most users miss an important step with their default Apache installation on their server or instance in the cloud. The biggest misunderstanding is that Apache will work out of the box perfectly with any server size. This is wrong. The default Apache settings require quite a bit of server resources and if you do not have them, which you won’t likely will not. This calculation uses your available ram to calculate Apache’s prefork MPM settings. The calculation out something like this: (Total Memory – Critical Services Memory) / Size Per Apache proces.

The idea of making this calculation is to ensure that Apache leaves enough memory for your system to use and not starve other processes such as MySQL.

From httpd.conf:

prefork MPM

  • StartServers: number of server processes to start
  • MinSpareServers: minimum number of server processes which are kept spare
  • MaxSpareServers: maximum number of server processes which are kept spare
  • ServerLimit: maximum value for MaxClients for the lifetime of the server
  • MaxClients: maximum number of server processes allowed to start
  • MaxRequestsPerChild: maximum number of requests a server process serves

Now the best way to tweak this is to understand how much each Apache process is using currently and take that number into consideration. For example if you have the following configuration:

<IfModule prefork.c>
 StartServers       10
 MinSpareServers    10
 MaxSpareServers   10
 MaxClients       10
 MaxRequestsPerChild  4000

For example the above configuration would keep at a minimum 10 processes running at any given time (Start Servers) which you also only allow a max of 10 to serve your clients (Max Clients).  In this case MinSpareServers and MaxSpareServers should not come into play. After a single process serves 4000 requests it will be terminated and another called to replace it based on the MaxRequestsPerChild directive.

So assume that you have 1.7GB of memory to work with which is in line with an m1.small instance on Ec2. So lets say that you have 60MB per process average httpd. Assuming 200MB for O/S and other services (more if running MySQL), you have 1.5GB – lets leave about 10% spare which would give you about 23 processes max. So lets try:

<IfModule prefork.c>
 StartServers       5
 MinSpareServers    2
 MaxSpareServers   5
 MaxClients       23
 MaxRequestsPerChild  2000

These optimizations are necessary if you want to have a smooth running server and to endure a large traffic spike. I also suggest taking a look at MySQL optimization if you are running a local SQL server and not remote like RDS. I do not have specific steps detailed here but I have provided a resource to take a look at.


Next I would like to take a look at empowering WordPress to use a CDN in the cloud like AWS CloudFront or any other service you choose. For the purposes of this tutorial I used CloudFront. We can do this with a WordPress Plugin called W3 Total Cache. Go ahead and install this plugin onto your WordPress installation and take a look at the CDN options. To setup your W3 Total Cache plugin to use CloudFront, select “Performance” then “General Settings,” then scroll down to CDN, then check the enable box and switch the drop down menu to Amazon CloudFront under Origin Pull. Then press save. Once saved go to “Performance” then “CDN” and add your AWS Access Key and Secret key which can be found here.



You can either press “Create Distribution” from the plugin to create your CloudFront Distribution or you can do it manually via the AWS Console. Please be patient, your CloudFront distribution will take anywhere from 15-30 minutes to create on AWS. Once finished you can save and test your settings. You should then see your code change when you view source in any browser to include your custom cname or the distribution ID.

Now I do recommend that you use CNAMEs, and at least 2-3 of them because this will speed up page load time by giving your browser different CNAMES to point at and open up parallel download threads that will increase overall page rendering time.

Now using a CDN is only the first step, there are many other options in the plugin to increase speed. You should also enable the Page Cache options, database caching, and minify. Please read about each option in the support tab of W3 Total Cache here “” I may add to this tutorial in the future but this should give you a head start. Also remember to test your performance with Pingdom afterwards.