How to Disable OPcache for a Specific Domain

OPcache is a built-in PHP extension that improves performance by storing precompiled script bytecode in memory. While ideal for production environments, it can be a hassle during development when you need to see real-time changes to your PHP code.

If your server is using the mod_lsapi PHP handler (commonly used with cPanel), you can disable OPcache on a per-domain basis. This guide walks you through how to do that safely and effectively.

Why Disable OPcache Per Domain?

You may want to disable OPcache for a domain if:

  • You're developing or testing and want to see immediate file changes.

  • You're troubleshooting PHP behavior and want to rule out caching issues.

  • You want to selectively disable caching without affecting the whole server.

Requirements

This method applies if:

  • You're not using PHP-FPM.

  • Your PHP handler is set to mod_lsapi (check via MultiPHP Manager in cPanel).

  • You have access to the domain's root directory (via cPanel File Manager, FTP, or SSH).

Step-by-Step Guide

Step 1: Locate or Create the .htaccess File

  1. Go to the root folder of the domain (commonly public_html or a subdirectory).

  2. Look for a file named .htaccess.

    • If it doesn’t exist, create a new one named .htaccess.

Note: If you're using a File Manager, make sure "Show Hidden Files" is enabled.

Step 2: Add OPcache Directive

Inside the .htaccess file, add the following line:

php_flag opcache.enable Off

This disables OPcache for all PHP scripts running under that directory and any subdirectories.

Step 3: Save Changes and Test

  1. Save the .htaccess file.

  2. Clear your browser cache.

  3. Make a change to a PHP file on the domain, refresh the browser, and confirm the update shows immediately.

Troubleshooting

If OPcache still seems to be active:

  • Make sure the .htaccess file is in the correct directory (where the site's entry point index.php lives).

  • Confirm that the domain is using the mod_lsapi handler (check in MultiPHP Manager).

  • Avoid using .user.ini or custom php.ini to disable OPcache — they often don’t work reliably with mod_lsapi.

Optional: Exclude Files or Folders Instead of Disabling

If you prefer to keep OPcache enabled but exclude specific scripts or directories:

  1. Create a file, e.g. opcache-blacklist.txt, and list file paths or patterns:

    /home/user/publichtml/dev/*
    /home/user/publichtml/test.php
  2. In your OPcache configuration, add:

    opcache.blacklist_filename=/path/to/opcache-blacklist.txt

This lets you fine-tune caching by bypassing specific files.

If you're unsure what PHP handler your domain is using or need help locating the correct configuration files, consult your hosting provider or server administrator.



Still need help?

Contact us

cPanel