WordPress Optimization

WordPress can be optimized, but it is best to take a layered approach, and start with the hardware and the network, then work one's way up through the operating system, the web server, php, mysql/mariadb, and finally at the wordpress configuration level. Each level has parameters for success, and any given level can contribute to bottlenecks, slowness, and annoyance.

Layer 0, the Network

Before even getting to hardware (the server/vps), a decent network needs to be determined. Decent means that the network (and/or datacenter where the server lives) will have uptime and throughput needed and anticipated, for a reasonable price.

There are also legal issues with location of servers, so that is important as well.

Layer 1, The Hardware

Now we are talking about basic features of processors and memory, as well as disk capacity and speed.

There is a layer of virtualization, say 1.5 (Xen vs. KVM virtualization hypervisor). Lots of opinion on this but KVM is supposed to be better by some reckoning. Note, sometimes there is a bare metal option or something exotic. I'm not there yet.

Layer 2, The Operating System

CentOS 7 and Ubuntu are the two most popular. I'm used to CentOS more, but Ubuntu is quite popular. For less popular distributions there are fewer documents available to help.

Also, there may be a 2.5 layer of containerization, Docker and such. Again, not using this, but it is likely very important for performance, as well.

Here securing the system is the first task, then management configuration, then performance tweaks.

layer 3, Application Layers

These all interoperate, but basically we can start with the communication chain of Web server, Scripting language, Database server. In my case, it is standard LAMP:

  • Linux (layer 2)
  • Apache
  • MySQL (MariaDB)
  • PhP

But even before the applications are configured, there can be a management layer to help out. A great one in Webmin and its sister product Virtualmin for managing multiple virtual sites/accounts (akin to WHM and Cpanel, but done correctly).


Pre-Apache is stuff like Varnish and Memcached, though they are connected into Apache (Apache needs to be aware of them or configured to interoperate in some way).

Note that this resource is one of the best for optimizing wordpress (and all the app-level stuff), though it is a kitchen sink approach. Memcached, Varnish and PHP-FMP stuff there, plus how to deal with Cpanel.

Apache Web Server

Now, Apache is quite a bear, but it is a known bear, so I stick with it (and can get it to do what I want in the circumstances I use it. But how to configure it. Every time I have to do some new install, the questions rear their ugly head again, what is fast and secure?

Note: WHM/Cpanel sucks, so use include files so the braindead thing doesn't overwrite. Read more about the suckiness (and how to configure in spite of it).

Turns out that there are many opinions on this, but this is what I've gone with currently:

These are event handlers and how Apache processes requests.


  • PHP-FPM -or- Fcgid

Memory settings:


define('WP_MEMORY_LIMIT', '128M');
define( 'WP_MAX_MEMORY_LIMIT', '256M' );


memory_limit = 128M ; Maximum amount of memory a script may consume (128MB)

.htaccess php_value memory_limit 128M