+254725682556 +254725052660 [email protected]
Client Area

Hosting

How to Clear PHP OPcache After Updating Your Website's Code

You uploaded a code change, updated a theme file, or deployed through Git, but your website still behaves like the old version even after you've cleared your browser cache. This is usually not a caching problem in your browser at all. It's PHP's OPcache on the server holding on to a compiled copy of your old code.

What OPcache Is and Why It Hides Your Changes

OPcache stores a pre-compiled version of your PHP files in server memory so pages load faster. It's a good thing for performance, but it normally only refreshes a file when it notices the file's timestamp has changed. Depending on how you uploaded the file (some FTP clients, Git deployments, or file syncs preserve the original timestamp) OPcache may never notice the update, and keeps serving the old compiled version until it's cleared or the server restarts PHP.

This is a different issue from browser cache or CDN cache, which affect what a visitor's browser or a service like Cloudflare shows them. OPcache is server-side and affects everyone who visits your site, including you in a private browser window.

How to Clear OPcache

Shared hosting accounts don't have direct access to restart PHP-FPM, but switching the PHP version for your domain forces a restart of its PHP process, which clears OPcache along with it.

In cPanel

  1. Log in to cPanel and open MultiPHP Manager (or Select PHP Version, depending on your account).
  2. Select the domain whose code you just updated.
  3. Note the current PHP version, then change it to any other available version and click Apply.
  4. Switch it straight back to the original PHP version and click Apply again.
  5. Reload your website. The PHP process has restarted, and OPcache no longer holds the old files.

In DirectAdmin

  1. Log in to DirectAdmin and open Select PHP Version under your account.
  2. Note the current PHP version for the domain, switch it to a different version, and save.
  3. Switch it back to the original version and save again.
  4. Reload your website to confirm the update now appears.

Clearing OPcache From Your Own Code

If your site has SSH access or you can upload a one-off PHP file, you can clear OPcache directly without touching the PHP version:

  1. Create a small file, for example clear-cache.php, containing only: <?php opcache_reset(); echo "OPcache cleared"; ?>
  2. Upload it to your site's root folder and visit it once in your browser.
  3. Delete the file from the server as soon as it has run.
Don't leave this file on your server. Anyone who finds its URL could run it and reset your cache repeatedly, which isn't dangerous on its own but is unnecessary exposure.

If your update still doesn't appear after clearing OPcache, check whether a caching plugin, your browser, or a CDN is involved instead: see Why Your Website Changes Aren't Showing Up (and How to Clear Each Type of Cache) for how to rule out each layer.