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

Top Ten WordPress Configuration TipsA 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

WordPress Configuration TipsInstalled 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.

Top Ten WordPress Configuration Tips

If you want to read a detailed comparison of Apache and Nginx, there’s a very good article on Nginx.com. Converting your website to Nginx is fairly simple and can be done using your existing VPS. There’s a detailed guide on Digital Ocean for upgrading from Apache to Nginx.

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.

Installing Percona is very simple, the basic commands on Ubuntu are as follows (you can read more details on Percona’s site):

wget https://repo.percona.com/apt/percona-release_0.1-3.$(lsb_release -sc)_all.deb

sudo dpkg -i percona-release_0.1-3.$(lsb_release -sc)_all.deb

sudo apt-get update

sudo apt-get install percona-server-server-5.7

 

5. Implement HTTP/2

WordPress Configuration TipsHTTP 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.
  • Prioritization – HTTP requests can be assign dependency levels so the server can return higher priority requests faster.
  • 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:

listen 443 ssl http2 default_server;
listen [::]:443 ssl http2 default_server;

If you want to confirm if your site or another supports HTTP/2, KeyCDN is quick test tool for HTTP/2.

4. Make sure you are running on SSD Storage

cloud iops comparisonI’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.

Several smaller cloud providers offer SSD based servers including:

I’m a big fan of Digital Ocean, their SSD servers have amazing performance. We compared SSD storage a few months ago and detailed how good Digital Ocean’s strong performance.

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.

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

client_body_buffer_size 10K;
client_header_buffer_size 1k;
client_max_body_size 10m;
large_client_header_buffers 2 1k;

 Set Nginx Timeouts

Set request timeouts in Nginx to improve overall performance and prevent bad requests from impacting the server.

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

client_body_timeout 12;
client_header_timeout 12;
keepalive_timeout 15;
send_timeout 10;

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

# Allow the full range of ports.
net.ipv4.ip_local_port_range = 1024 65535

# Enable fast recycling of sockets in TIME_WAIT
net.ipv4.tcp_tw_recycle = 1

# Allow sockets in TIME_WAIT to be reused for new connections
net.ipv4.tcp_tw_reuse = 1

# Increase memory per socket to 16MB.
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216

# Bump up number of outstanding syn requests allowed.
net.ipv4.tcp_max_syn_backlog = 4096
net.ipv4.tcp_syncookies = 1

# Increase max number of backlogged sockets from 128 to 1024.
net.core.somaxconn = 1024

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.

Using Let’s Encrypt you can easily configure your webserver to use the Let’s Encrypt Certificate Authority and generate your certificate. The process is covered in their documentation. You’ll also want to look at the CertBot server client.

1. Enable Gzip Compression

Top-10-Wordpress-Tips-Compression_jfs6wyFor 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:

  1. Edit /etc/nginx/nginx.conf
  2. Find the Gzip Setting section and modify that section to match this:
    ##
    # Gzip Settings
    ##
    
    gzip on;
    gzip_disable "msie6";
    
    gzip_vary on;
    gzip_proxied any;
    gzip_comp_level 6;
    gzip_buffers 16 8k;
    gzip_http_version 1.1;
    gzip_min_length 256;
    gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/vnd.ms-fontobject application/x-font-ttf font/opentype image/svg+xml image/x-icon;
    
  3. Save and close nginx.conf
  4. Test your nginx.conf for any typos using sudo nginx -t
  5. If no errors restart Nginx: sudo service nginx restart
  6. You should immediately see improved performance.

 

Byron Pate
I am Byron Pate, and I’m a technology enthusiast. I work in Atlanta, Georgia as a Solution Architect. I write about technology, troubleshooting, and infrastructure.
We will be happy to hear your thoughts

      Leave a reply