Skip to content

Sane PHP OPcache settings for cPanel production servers

Realistic OPcache values for a cPanel server running mixed PHP workloads, why the cPanel defaults are too conservative on a busy box, and how to size opcache.memory_consumption against real measurement.

OPcache is the single largest PHP performance win on a cPanel server, and the cPanel defaults leave most of that win on the table. The default opcache.memory_consumption=64 and opcache.max_accelerated_files=4000 are sized for a single small site, not a shared host running 50 WordPress installs and a Magento. Bumping these is safe, cheap, and reversible — and the metric to drive it is not a guess but opcache_get_status().

What’s happening

OPcache caches the bytecode of every PHP file PHP touches, keyed by the file path. When the cache fills, OPcache resets entirely — for one request the box looks like every site needs to recompile from scratch. max_accelerated_files caps the number of distinct files cached; memory_consumption caps the bytes. Either ceiling triggers a reset. On a server with 50 WordPress installs, the file count alone is easily 30k–50k.

How to verify

From any of the running PHP-FPM workers, get the live OPcache stats:

php -r 'print_r(opcache_get_status(false));' 2>/dev/null | head -40
php -r 'print_r(opcache_get_configuration());' | grep -E "memory_consumption|max_accelerated"
grep -r "opcache" /opt/cpanel/ea-php82/root/etc/

The keys that matter: cached_scripts, num_cached_keys, max_cached_keys, memory_usage.used_memory, memory_usage.free_memory, opcache_statistics.oom_restarts, opcache_statistics.hash_restarts. A non-zero oom_restarts means memory is too small; a non-zero hash_restarts means max_accelerated_files is too small.

The fix

  1. WHM > MultiPHP INI Editor > Editor Mode > pick the PHP version > set:
    opcache.enable = 1
    opcache.enable_cli = 0
    opcache.memory_consumption = 256
    opcache.interned_strings_buffer = 16
    opcache.max_accelerated_files = 20000
    opcache.validate_timestamps = 1
    opcache.revalidate_freq = 60
    opcache.save_comments = 1
    opcache.fast_shutdown = 1
  2. Reload the FPM pool: systemctl reload ea-php82-php-fpm.
  3. Watch opcache_get_status() again after 30 minutes of normal traffic. num_cached_keys should be well below max_cached_keys and growing slowly; memory_usage.free_memory should not drop below 20% of the total. If it does, double the value of whichever is short.
  4. Resist opcache.validate_timestamps = 0 unless you have a deployment pipeline that explicitly resets OPcache after a code push. The performance gain is real but the operational cost — “I deployed and nothing changed” tickets — is much higher than the gain on a managed cPanel server.
  5. For sites with a deploy step, expose opcache_reset() through a one-off URL protected by IP allowlist, or just systemctl reload ea-php82-php-fpm from the deploy script. Reloading the pool clears OPcache; restarting is overkill.
  6. Document the values. A future upgrade may reset them; the documentation is the source of truth.

For environments where OPcache tuning is part of routine maintenance, Stack Harbor sets per-version baselines and audits opcache_get_status() weekly under cPanel server management.