// blog

How to Configure PHP OPcache for Maximum Performance: A Practical Guide

August 20, 2026 · by CLIQHOST

How to Configure PHP OPcache for Maximum Performance: A Practical Guide

If you run a WordPress, Joomla, or any PHP-based application and want to speed it up without investing in additional hardware, PHP OPcache is one of the most effective tools available. Bundled with PHP since version 5.5, it can reduce server response times by 50–80% with just a few configuration changes.

In this guide, you'll learn exactly what OPcache does, how to enable it, and how to configure it properly — whether you're on an NVMe VPS with root access or a cPanel shared hosting environment.


What Is PHP OPcache and How Does It Work?

Every time your server receives a PHP request, the interpreter must:

  1. Read the .php file from disk
  2. Compile it into bytecode
  3. Execute the bytecode
  4. Return the response

Steps 1 and 2 happen on every single request, even when the code hasn't changed. OPcache eliminates recompilation by storing the compiled bytecode directly in RAM. On subsequent requests, PHP skips straight to execution.

The result: lower CPU usage, faster response times, and higher throughput capacity.


Step 1: Check if OPcache Is Active

On an SSD VPS with SSH access, run:

php -r "echo opcache_get_status() ? 'OPcache active' : 'OPcache inactive';"

Alternatively, create a temporary PHP info file:

echo '<?php phpinfo(); ?>' > /var/www/html/info.php

Open https://yourdomain.com/info.php in your browser and look for the Zend OPcache section. Delete the file immediately after checking — it exposes sensitive server information.

On cPanel, you can check active extensions via MultiPHP INI Editor or PHP Selector.


Step 2: Enable OPcache (If Not Already Active)

On a VPS / Dedicated Server (php.ini)

Locate your php.ini file:

php --ini | grep "Loaded Configuration"

Open the file and add or uncomment:

extension=opcache
zend_extension=opcache

Restart PHP-FPM or Apache:

# For PHP-FPM
systemctl restart php8.2-fpm

# For Apache with mod_php
systemctl restart apache2

On cPanel (MultiPHP INI Editor)

  1. Go to cPanel → MultiPHP INI Editor
  2. Select your domain and PHP version
  3. Find opcache.enable and set it to 1
  4. Save changes

Step 3: Optimal OPcache Settings

This is where the difference lies between an active OPcache and a well-configured one. Add these directives to your php.ini or a dedicated file like /etc/php/8.2/fpm/conf.d/10-opcache.ini:

; Enable OPcache
opcache.enable=1
opcache.enable_cli=0

; Allocated memory (MB) — recommended: 128–256 MB
opcache.memory_consumption=128

; Interned strings buffer size
opcache.interned_strings_buffer=16

; Maximum number of cacheable files
opcache.max_accelerated_files=10000

; Revalidation interval (seconds). 0 = manual reset only
opcache.revalidate_freq=60

; Timestamp validation (1 = yes, 0 = max perf, manual reset needed)
opcache.validate_timestamps=1

; Save comments (required by some annotation-based frameworks)
opcache.save_comments=1

; Disk-based file cache (fallback after server restart)
opcache.file_cache=/tmp/opcache
opcache.file_cache_consistency_checks=1

Key Settings Explained:

Directive Recommended Value Explanation
memory_consumption 128–256 MB RAM reserved for bytecode cache
max_accelerated_files 10 000–20 000 WordPress + plugins = thousands of files
revalidate_freq 60 (prod) / 0 (dev) How often to check for file changes
validate_timestamps 1 Auto-detect modified files

Step 4: OPcache for WordPress — Specific Recommendations

A typical WordPress install with plugins can generate 3,000–8,000 PHP files. Add WooCommerce, child themes, and page builders, and that number climbs quickly.

Recommended settings for a WordPress site on optimized WordPress hosting:

opcache.memory_consumption=192
opcache.max_accelerated_files=15000
opcache.revalidate_freq=300
opcache.fast_shutdown=1

After every theme or plugin update, manually flush the OPcache. A simple script:

<?php
if (function_exists('opcache_reset')) {
    opcache_reset();
    echo 'OPcache successfully flushed.';
}

Or using WP-CLI (recommended on a VPS):

wp eval 'opcache_reset();' --allow-root

Step 5: Monitor OPcache Status

Get detailed statistics with opcache_get_status():

<?php
$status = opcache_get_status();
echo 'Memory used: ' . round($status['memory_usage']['used_memory'] / 1024 / 1024, 2) . ' MB\n';
echo 'Cached scripts: ' . $status['opcache_statistics']['num_cached_scripts'] . '\n';
echo 'Hit rate: ' . round($status['opcache_statistics']['opcache_hit_rate'], 2) . '%\n';

A healthy hit rate is above 90%. If it's lower:
- Increase memory_consumption
- Increase max_accelerated_files
- Check whether validate_timestamps is causing frequent cache invalidations

For a visual dashboard, install the free opcache-gui tool directly on your server.


Step 6: OPcache in Production vs. Development

Production (recommended)

opcache.validate_timestamps=1
opcache.revalidate_freq=300

Local Development

opcache.validate_timestamps=1
opcache.revalidate_freq=0

Or disable OPcache entirely in dev to see changes instantly:

opcache.enable=0

On a production NVMe VPS, never set both revalidate_freq=0 and validate_timestamps=0 simultaneously without an automated cache reset mechanism on deploy.


Common Mistakes and How to Avoid Them

1. Insufficient Memory Allocated

If memory_consumption is too low (e.g., 32 MB), the cache fills up quickly and performance degrades. Check real usage with opcache_get_status() and adjust accordingly.

2. max_accelerated_files Too Low

The default value of 2,000 is insufficient for WordPress. Set it to at least 10,000.

3. Forgetting to Reset Cache After Deployment

If you update PHP files but OPcache is still serving the old version, you'll see unexpected behavior or errors. Integrate opcache_reset() into your deploy script or CI/CD pipeline.

4. OPcache on Shared Hosting Without Isolation

On quality shared hosting — like CLIQHOST's cPanel hosting — OPcache is configured with per-user isolation, meaning one account's cache cannot affect another.

For full server management support and custom OPcache tuning, consider our server management services.


OPcache + Other Caching Layers: The Winning Stack

OPcache optimizes PHP execution (server-side). For complete performance, combine it with:

  • Redis — object and session caching
  • CDN — for static assets (images, CSS, JS)
  • Page cache (W3 Total Cache, WP Rocket) — store generated HTML
  • Gzip/Brotli compression at the Nginx/Apache level

This combination can bring response times below 200ms even under heavy traffic. If you need full control over your entire stack, a managed dedicated server gives you the resources and flexibility to fine-tune every layer.

For more performance tips and server guides, visit the CLIQHOST blog.


Conclusion

PHP OPcache is one of the simplest and most impactful optimizations you can make for any PHP server. A few well-chosen directives in php.ini can significantly reduce CPU load and improve response times at zero additional cost.

The essential steps:
1. Verify OPcache is enabled
2. Allocate enough RAM
3. Set max_accelerated_files to match your application's size
4. Reset the cache after every deployment or update
5. Monitor the hit rate and tune periodically

If you want a hosting environment where OPcache is correctly configured from day one, explore NVMe VPS plans or WordPress hosting from CLIQHOST — or contact us for a custom server setup.

SHARE
// what clients say

What Our Clients Say

Real reviews from customers who trust CLIQHOST for performance, reliability and expert technical support.

★★★★★

"We moved our online shop from a foreign host and the difference is night and day — pages load instantly and support replies in minutes, in Romanian."

AM
Andrei M.
eCommerce owner · Chișinău
★★★★★

"Migrated 12 client sites to CLIQHOST. Free migration, zero downtime, and the cPanel setup is exactly what my team needed. Highly recommend."

EV
Elena V.
Web agency · Bălți
★★★★★

"Our NVMe VPS handles traffic spikes without a sweat. Full root, local datacenter, and billing in MDL — everything we wanted from a provider."

DC
Dmitri C.
SaaS founder · Chișinău