Hosting·5 min read

Setting the PHP version, OPcache and LiteSpeed Cache with the assistant

The three settings that together make the biggest difference to the speed of your site, where you set them, in what order, and what goes wrong when you set them in two places at once.

Check which PHP version this website runs, whether OPcache is on and
whether LiteSpeed Cache is set up properly. Tell me what you find
first, do not change anything yet.

There are three settings that together almost always make the biggest difference to the speed of a PHP site: the PHP version, OPcache, and the page cache. They are separate from each other, they are set in different places, and all three regularly end up half arranged.

This article is about the setup itself. If you are looking for where the slowness comes from, start with the checklist for a slow WordPress site; that walks through every layer and points you at the one that matters for you.

Look first, change second

Always start with an inventory. Flipping three settings at once and measuring afterwards tells you nothing, because you do not know which one did it. And if something breaks, you do not know what to put back.

Have the assistant list what is there now: the PHP version of this website, whether OPcache appears in the list of extensions, the PHP memory limit, and whether a caching plugin is active. That is one instruction and it takes half a minute.

1. The PHP version

Run the newest stable PHP version your site can handle. Not the very newest that exists, but the newest that your plugins and theme say they support.

You set the version in the PHP menu of your hosting panel, per website. Not in an .htaccess, not in a wp-config.php. If it is set in two places, which one wins is unpredictable, and you will spend half an hour hunting for something you did yourself.

Which PHP version does this website run now, which versions are
available, and check whether my plugins and theme can handle the next
one before we switch.

A version jump is a change you can undo: you set it back in the same menu. Do it at a quiet moment and check the site straight afterwards, including a page with a form and the admin area.

If you have one folder or one subsite that has to stay on an older version, that can be arranged separately. Do not put the whole website back because one thing refuses to come along.

2. OPcache

OPcache is the least visible of the three and often the biggest win. Without OPcache, PHP reads and compiles all of your code again on every visit. With OPcache that happens once and after that it comes out of memory.

You turn it on under the extensions in that same PHP menu. If you do not know whether it is on, have it checked.

Is OPcache on for this website? If not, turn it on and then show me
that it is really active.

Two things to know once it is on:

A change to a file can take a moment to arrive. That is not a bug, that is the cache still holding the old version. When you update plugins or upload a theme, it is wise to clear the cache afterwards.

OPcache has its own memory area and it can fill up. A site with many plugins and a page builder can want to put more in it than fits. The cache then gets emptied and refilled over and over, and you are worse off than without it. That is worth having checked when a site suddenly got slower rather than faster after adding plugins.

3. LiteSpeed Cache

The web server on our hosting does the page caching itself. The LiteSpeed Cache plugin flips that switch and gives you the buttons; it does not build a cache in PHP of its own. That is exactly why it works: a cached page is served without WordPress or PHP being involved at all.

Install and activate the plugin, and leave the defaults alone at first. The temptation is to switch on every optimisation right away (combining css, deferring javascript, converting images). Do not do that in one go. Those are the settings that break layout, and if you enable them all at once you will not know which one did it.

Two settings you do choose deliberately:

How long a cached page is kept. Set it very long and a visitor gets a page that is days old. For a static page that is fine, but forms on such a page contain codes that are valid for less time than the page itself. How that goes wrong and what you do about it is in a submission that never arrives because of expired nonces.

Which pages must not be cached. A basket, a checkout, an account or login page belong there. Those are usually right by default, but if you have your own page with personal data, add it.

Turn on LiteSpeed Cache with the default settings, leave the
optimisations off for now, and clear the cache afterwards.

The assistant can clear the cache too: wp litespeed-purge all. That is the first thing you ask for when a change does not seem to show up.

Not seeing the cache does not mean it is not there

As an administrator you are logged in, and logged in users never get the cached page. So you always see the fresh version and your visitor may not.

View your site in a private window when you want to see what a visitor sees. The same goes for screenshots: a screenshot of your site is a visitor without a login and therefore does get the cache.

The order

  1. Look at what is there now and write it down.
  2. Set the PHP version and check the site.
  3. Turn on OPcache and check the site.
  4. Turn on the page cache, clear it, and check the site in a private window.
  5. Only then measure again.

One change at a time, and a quick look after each step. Slower on paper and faster in practice.

Common mistakes

Setting the PHP version in two places. In the PHP menu and in an .htaccess. One of them wins and it is rarely the one you meant.

Turning on OPcache and not clearing the cache after an update. Then old code runs while the new code is already there.

Enabling every optimisation of the caching plugin at once. If something breaks, you have ten suspects.

Keeping the cache for a very long time while there are forms on the page. Visitors get a form that no longer works, and you hear nothing about it.

Checking whether the cache works while logged in. Logged in administrators never get served the cache.

Changing everything at once and measuring afterwards. Then you know it got better and not what did it, so you also do not know what to do on the next site.

MK
Maarten Keizer

Founder of Invoker. Over twenty years in hosting, system administration and web development; builds the Claude hosting himself and tests everything on our own servers first.

about maarten