Question

Nginx best high performance caching configuration for WordPress

I am planning to deploy an optimized LEMP stack on DigitalOcean on Ubuntu 18.04 for my WordPress site. I have many question and confusion related to caching. I hope I will get all my answer here.

  1. Are PHP-FPM and Varnish technology the same. Which one should I go for, Varnish or PHP-FPM for my Nginx server?

  2. According to my research, a combination of Redis and PHP-FPM gives best performance. Is this right or should I go for radis+varnish?

  3. As I know, Redis cache database query. So, if Redis only cache database then how PHP-FPM/Varnish works together with Redis to produce the web page very fast?

  4. As I know Nginx can’t process PHP request, so by default PHP-FPM comes here to serve the PHP request, Right? If right then PHP-FPM should already be configured in all the server set up. Am I right? I am using all the DIGITALOCEAN tutorials to set-up my server.

  5. After all the above set-up, do I need to use any caching plugin on top of my website?, e.g., WP-rocket or Swift Pro.

  6. A caching plugin also generates static HTML pages of a website and saves it on the server as PHP-FPM or Varnish do. So why we should use both caching plugin and server-level cache?

  7. Without installing a caching plugin, will my website give browser cache facility with the above set-up? Or it is necessary to use plugin to get the browser caching facility.

If you have more recommendation then please guide me. Thank you!


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Bobby Iliev
Site Moderator
Site Moderator badge
August 27, 2019
Accepted Answer

Hello,

I’ll try to answer all of your questions:

  1. PHP-FPM and Varnish are not the same in any way, you should not confuse the two, they can not substitute each other. Varnish is simply a HTTP accelerator it would simply cache your HTTP requests. PHP-FPM on the other side is actually going to do some work and is going to be processing your PHP requests passed from Nginx.

  2. Yes PHP-FPM and Redis is a great combination, just make sure that you have enough RAM available for Redis on your droplet or try suing the new Redis managed databases provided by DigitalOcean. You can of course add Varnish on top of that but it can not be a substitution for PHP-FPM in any way, it would only stay on port 80 and proxy all of the traffic to Nginx.

  3. Yes, you can configure PHP-FPM to work with Redis with the PHP-FPM redis extension

  4. Yes this is correct, Nginx would basically be proxying the PHP requests to PHP-FPM. It is configured in the LEMP droplet from the marketplace and it is included as a step in the tutorials.

  5. Yes, you can always add a caching plugin. If you have Nginx + PHP-FPM + Redis it would be quite beneficial to use a plugin.

  6. PHP-FPM does not actually generate static pages but it processes your PHP requests. On the other side Varnish would do that but Varnish is only able to listen on port 80 so you would need to either configure another service to listen on port 443 (https) and proxy the connections to Varnish so that your site could have an SSL certificate.

  7. You don’t need a plugin for browser caching, you can configure that in your Nginx config.

My recommendation would be stick to Nginx + PHP-FPM + Redis + A caching plugin at first and see how it performs. Nginx is quite fast any way. As a test you could add Varnish as I already mentioned it does not support SSL, so you would need to either configure your Nginx to handle your https requests anyway and proxy to Varnish and then proxy back to Nginx, in this case you might have to do more tweaking to get the configuration and the proxying correct.

Hope that this helps! Regards, Bobby

Hello, 10k views and not many answers here.

Probably avoid Varnish. I see a lot of newbies asking about Varnish, and the correct answer is that if you are asking about it, then it means don’t use it. Because Varnish is rather complex and mostly only a good match for niche cases, like a custom cluster setup by a web hosting company for many clients/accounts. It is difficult to manage and can lead to conflicts. It is usually used for full-page caching, but this is pointless if you are using Nginx.

Redis OR Memcached. These are usually only used for object cache in Wordpress stacks, because if you use them for full page cache you will need a lot of RAM memory and it can quickly run out if not. For object cache they are similar, Redis is more powerful if you know how to setup the correct settings, or follow a guide.

https://wordpress.org/support/topic/redis-vs-memcached-for-wordpress-cache/

USE NGINX FASTCGI CACHE. I still don’t know why this is ignored by so many tutorials and discussions about WordPress performance. If you want top performance than stop using goofy cache plugins, and let Nginx do what it was designed to do… rapid delivery of cached files.

PHP-FPM required for Nginx. There is no other option if you are running Nginx (which you should be, it is faster than Apache and Litespeed and free and open source).

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel