📄
Webhosting

Setting Up PHP OPcache for a Faster Website

📅 12 October 2026 ✏️ 12 October 2026 ⏱ 5 min leestijd

What is PHP OPcache, why does it speed up your website, and how do you configure it correctly on your hosting environment? Practical explanation and step-by-step plan.

PHP OPcache is a built-in caching feature of PHP that stores compiled script code in server memory, so PHP files don’t need to be translated again with every page view. This makes your website noticeably faster, especially with CMS systems like WordPress and WooCommerce that load many PHP files. In this article, you’ll learn exactly what OPcache does, how to enable and configure it, and how to check whether it’s working properly.

What is PHP OPcache?

Normally, a PHP file is read again and converted to machine code (compiled) on every visit, before the server can execute it. This costs time and server load, especially on busy websites. OPcache stores the compiled version of your PHP code in memory, so the server can reuse it directly on a subsequent request instead of compiling it again.

The result: shorter processing time per page request, less CPU usage, and a lower Time To First Byte. OPcache is part of PHP itself and doesn’t need to be installed separately, but it does need to be enabled and properly configured.

Why is OPcache important for speed?

Without OPcache, the server repeats the same work with every page request: reading, interpreting, and compiling files. With a website that has many plugins or a heavy theme, as is often the case with WordPress and WooCommerce, this adds up quickly. With OPcache, this step is largely eliminated once the code is in memory.

You’ll mainly notice this in:

  • Lower server load with many simultaneous visitors
  • Faster loading times for the backend, such as the WordPress admin panel
  • Less chance of timeouts on heavy pages such as a shopping cart or checkout

OPcache works at a different level than page caching (such as LiteSpeed Cache): it speeds up the processing of PHP code itself, while page caching stores complete HTML output. Both complement each other and don’t exclude one another.

💡 Tip: Always combine OPcache with an object cache like Redis if you have many database queries, for example with a webshop with many products.

Setting up OPcache: step-by-step plan

On most modern hosting environments, OPcache is already enabled by default, but the settings aren’t always optimally tuned to your website. Via Plesk, you can easily check and adjust this.

1

Open the PHP settings

In Plesk, go to your domain and click ‘PHP Settings’ to view the current configuration.

2

Check if OPcache is active

Look for the setting opcache.enable and set it to ‘On’ if it isn’t already.

3

Set the memory

Adjust opcache.memory_consumption to a value that matches the size of your website. A smaller website needs less memory than a webshop with many plugins and themes.

4

Set validate_timestamps correctly

With opcache.validate_timestamps set to ‘On’, PHP automatically checks whether files have changed. This is useful in a development environment; on a production site, you can turn this off for extra speed, provided you manually clear the cache after making changes.

5

Restart PHP-FPM or the web server

After adjusting settings, the PHP service needs to be restarted so the changes take effect.

Checking OPcache and troubleshooting

You can easily check whether OPcache is working by creating a phpinfo() file and looking for the ‘Zend OPcache’ section. There you can see whether the module is active and which settings apply.

If you do run into problems, watch out for these common situations:

  • Code changes aren’t visible: this is usually because validate_timestamps is turned off. Manually clear the OPcache or temporarily turn the setting back on.
  • Website becomes slower instead of faster: the allocated memory is probably set too low, causing the cache to be cleared and rebuilt repeatedly.
  • Errors after a plugin or theme update: clear the OPcache after major changes to your website, so old compiled code doesn’t linger.

Not sure whether your server environment is properly configured, or want to switch to a hosting provider where these kinds of settings have already been optimized for you? Check out the options for web hosting or read how switching to Tandata works.

Frequently Asked Questions

Is OPcache the same as page caching?

No. OPcache speeds up the compiling of PHP code, while page caching (such as LiteSpeed Cache) stores complete pages as HTML. They work together but do different things.

Do I need to install OPcache myself?

No, OPcache has been a standard part of PHP since version 5.5. You only need to enable and configure it.

Can OPcache cause problems with WordPress updates?

Sometimes you’ll still see old code active after an update. In that case, clear the OPcache or restart PHP-FPM to refresh the cache.

Does OPcache also work with WooCommerce?

Yes, especially with webshops with many plugins and dynamic content, OPcache helps reduce server load.

Conclusion

PHP OPcache ensures that your server doesn’t need to recompile PHP code over and over, which directly results in faster loading times and less server load. By properly setting the memory and clearing the cache after major changes, you keep your website running smoothly and stably.

View web hosting →

Was dit artikel nuttig?