Top Ten WordPress Configuration Tips

When it comes to configuring WordPress there’s a wealth of information available on how to do this. There’s so many variations on how WordPress is used today, that its hard to define one standard for how to configure your WordPress environment. As we described in the WordPress Infrastructure Architecture, there are many ways to deploy WordPress. The following WordPress configuration tips mostly apply to setting up self-hosted WordPress, but some can be helpful to managed WordPress environments.

Top Ten WordPress Configuration Tips

10. Use a Content Delivery Network

A CDN is a network of edge web servers located throughout the world that host static content. Given a single URL to a static resource, the CDN will resolve that to a server that’s closest to the browser.

The CDN options listed here are some of the more popular options, but there are quite a few others. CloudFlare works differently than the others, it routes all traffic through CloudFlare’s HTTP servers and caches your static content. AWS CloudFront is very popular as well because it has the large foot print of caching servers.

My personal preference is Cloudinary. Not only do that have a very full featured Free Pricing Tier, but they have a great plugin for inserting images into your posts.

9. Remove unused Plugins and Themes

Installed WordPress Plugins can add additional code execution to your website, and if its functionality you’re not even using, having the code executing is a waste of resources on your server and can potentially slow down your website. If you’re not using a plugin, deactivate it and then make it a habit to come back and delete deactivated plugins.

Since you can only have one Theme active at a time, you don’t have to worry about inactive Themes slowing down your website, but they do consume storage space on your server. And then you back them up and waste more storage on them. Interestingly, WordPress does not give you the ability to remove Themes from a website after installing it. So you’ll either have to delete the theme from wp-content/themes/ via WinSCP or the command line.

8. Switch to Nginx

The default and most common configuration for WordPress is to use Apache as the web server. But Nginx has increasingly become a very popular choice for WordPress, and for good reason. Nginx offers a number of benefits over Apache that are especially important for WordPress websites. Nginx was specifically created as an alternative to Apache for very busy websites. And today some of the busiest websites run Nginx. Some of the biggest benefits of Nginx are:

Nginx is a very lightweight web server. It runs very well even with minimal resources. Memory utilization on Apache is tied to connections, as the site gets busier your memory usage goes up. Nginx uses about the same amount of memory for 50 concurrent connections to 3000 connections.

Connection Handling – Apache spawns additional threads for each concurrent connection, but Nginx uses worker processes to handle connections, each work process can handle 1000s of requests. This lets Nginx easily handle even the busiest websites.

Configuration – Most administrators find the Nginx configuration system to be much easier to work with than Apache configs. Nginx’s server blocks make hosting multiple sites much easier. Nginx is much easier to configure other settings like HTTP/2 and SSL.

7. Enable Client Side Caching

One of my favorite WordPress Configuration Tips, this is a 5 minute change that can really improve performance. Even if you’re using a server side caching plugin like WP Rocket. You still need to ensure you are telling the browser to cache static files like images, stylesheets, and javascripts. By default static files are requested every page load and Nginx will serve them every them they are requested. By setting an expiration date on static files, they’ll be pulled from the browser’s cache. So setting this can ensure your page load time is as fast as possible.

In Nginx configuring client caching is pretty easy. In your server block setting the following and restart Nginx.

location ~* \.(jpg|jpeg|gif|png|ico|css|js)$ {
expires 365d;
}

Now Nginx will issue a 304 for those resources and tell the browser to use the cached copy, improving response time and saving bandwidth.

6. Use Percona

Percona Server is a popular fork of MySQL. Percona is much faster than traditional MySQL, is easier to tune and administer, and scales better on modern cloud infrastructure. The Percona team basically includes functionality that is only available in MySQL Enterprise in Percona Server for free. Percona also uses an enhanced version of the InnoDB storage engine called XtraDB. XtraDB is a faster more efficient storage engine than the default InnoDB.

Replacing the default MySQL installation on your WordPress server can give you a performance boost even on modest sites. If you have heavy traffic on your site, you will see even better performance. Percona is completely backwards compatible with MySQL and supports all the native MySQL client tools, but you get the benefit of Percona’s management tools.

5. Implement HTTP/2

HTTP Version 2 is a major update to the HTTP protocol. Its the first major revision since HTTP 1.1 was introduced in 1997. HTTP/2 was published as RFC 7540 in May 2015. By the end of 2015 all major browsers were supporting HTTP/2.

HTTP/2 Benefits Include:

Connection Optimization – HTTP/2 uses a single HTTP connection between the browser and the web server. This reduces the number web server round trips and ultimately improves performance.

Header Compression – HTTP Headers are compressed using HPACK. This reduces the size of each request which improves page load speed and consumes less bandwidth.

Binary Format – HTTP/2 uses a binary format to talk to the web server instead of text. This makes requests smaller and less likely to have problems.

Multiplexing – Multiple HTTP requests are allowed at the same time, on the same TCP connection. Previously, with HTTP/1.1, each transfer would have to wait for other transfers to complete.

Pushing – The HTTP/2 web server can push resources to the client’s cache for future request instead of waiting for the request.

For your WordPress site to make use of HTTP/2 your web server needs to be updated to utilize the newer protocol. Keep in mind that all the major browsers require that HTTP/2 connections be encrypted, so you must be running SSL on your site. HTTP/2 is another good reason for using Nginx. Updating Nginx to use HTTP/2 is extremely easy. If you are using Apache you need to be on Apache 2.4 17 and then install mod_http2. But for Nginx just ensure you are running Nginx 1.9.5 or higher, and then update your server block to add the http2 value like this:

4. Make sure you are running on SSD Storage

I’ve talked about several WordPress Configuration Tips that you do today to tune your environment, but this is really something to do when you are first setting it up. Nothing will make a more noticeable impact on your WordPress performance than moving your website and database onto an SSD VPS. Solid State Drives are 4 – 5 faster than Hard Disk Drives. Luckily it’s very easy to find SSD based virtual private servers today at reasonable prices. Both Azure and AWS offer SSD storage for their servers, but prices are $20 – $30 a month.

3. Tune for Performance

The other thing you’re going to need to do is optimize your configuration for WordPress by tuning your server configuration. The following WordPress Configuration Tips are configurations in Linux and Nginx you can tune to improve performance in medium to high traffic WordPress websites, but even if you have a small site you should be familiar with them.

Increase Nginx Worker Connections

By default the Nginx configuration is set to have a maximum of 768 simultaneous connections. Even on small VPS servers with 1GB or less of memory you should bump this up to 1024. On larger servers take it higher, on my 2GB server I use 7768.

I’m also going to use epoll as the Nginx event notification mechanism. This is the recommend mechanism for best server throughput. Also I’m going to enable multi_accept so that my worker process will accept all new connections at once.

Edit /etc/nginx/nginx.conf as follows:

events {
worker_connections 1024;
multi_accept on;
use epoll;
}

Increase Nginx Buffer Sizes

Allow Nginx to use larger buffer sizes to prevent it from having to read and write to disk. Even on SSD having to write out buffer data can slow down performance.

Disable Access Logging

If you are using Google Analytics to traffic website utilization (and you should be), then you don’t need to log every access. I keep error_log enabled for troubleshooting, but I find for most WordPress sites access logs are just a waste of storage.

Edit /etc/nginx/nginx.conf as follows:

access_log off;

Linux Kernel Socket Tuning

There’s a number of tweaks we can make to the way the Linux Kernel handles TCP Sockets to improve network performance. These are slight tweaks but they add up to help make your website have optimal performance.

Edit your /etc/sysctl.conf, add the following to the end, apply using sysctl -p, then restart Nginx

2. Setup Let’s Encrypt SSL

Most of the WordPress Configuration Tips I’ve covered are related to improving performance, but this tip improves security. Traditionally if you want to support HTTPS on your website you had to purchase a certificate from a Certificate Authority like Verisign, GoDaddy, or Comodo. Each certificate cost you $25 – $500 per year. This made it cost prohibitive for smaller websites to support HTTPS. Let’s Encrypt is a certificate authority that launched in April of 2016 that provides TLS certificates for no cost. Certificates can be automatically created by script, eliminating much of the complexity needed to register and renew certificates.

1. Enable Gzip Compression

For WordPress Configuration Tips, this is a no brainer step especially if you are running Nginx. Basically enabling compression sends compressed versions of the content over the Internet, which the browser decompresses and serves. Gzip compression is enabled by default in Nginx, but the default configuration doesn’t allow it to be really be leverage. And if you test your site it will most likely show that its not using server side compression. To setup compression do the following: