Every time PHP runs a script, it first compiles the code. OPcache stores the compiled code in memory so the next request skips that step. It is one of the easiest speed gains for any PHP site, and on CloudLinux hosting you control it in PHP Selector.
Before you start
- cPanel access with Select PHP Version.
- A numbered PHP version selected (see changing PHP version).
Check OPcache is enabled
- Go to cPanel → Software → Select PHP Version.
- In the extensions list, make sure opcache is ticked. It usually is by default.
- Confirm in WordPress under Tools → Site Health → Info → Server, or with a temporary
phpinfo()page.
Options you may see
In the Options tab, depending on the server, OPcache settings may be editable:
| Option | Meaning | Typical value |
|---|---|---|
opcache.memory_consumption | Memory for compiled code (MB) | 128 |
opcache.max_accelerated_files | Number of scripts that can be cached | 10000 or more for WordPress with many plugins |
opcache.revalidate_freq | Seconds between checks for changed files | 2–60 |
opcache.validate_timestamps | Whether to check files for changes at all | On (keep on for normal hosting) |
Note: OPcache memory counts toward your account's CloudLinux memory limit. Very large values do not help small sites; keep defaults unless you know you need more.
After deploying code
With validate_timestamps on, OPcache notices changed files after revalidate_freq seconds. If an update does not seem to take effect:
- Wait a minute, or
- Switch PHP version and back in Select PHP Version, which restarts your PHP processes, or
- Use a plugin or script that calls
opcache_reset().
OPcache and page caching
OPcache speeds up every PHP request; LiteSpeed Cache avoids PHP entirely for cached pages. Use both (see LiteSpeed Cache and LSAPI explained).
Troubleshooting
Old code keeps running after an update
Timestamps validation is off or revalidate frequency is long. Reset OPcache as above.
Site errors after enabling OPcache
Very rare; usually a broken extension combination. Disable recently added extensions and test (see PHP extensions).
Frequently asked questions
Does OPcache need configuration to work?
No. Enabled with defaults, it already gives most of the benefit.
Is OPcache shared between accounts?
No. Each account's PHP processes have their own cache inside their own environment.
What about the JIT in PHP 8?
JIT helps CPU-heavy code more than typical websites. Leave it at the server default.
How do I see OPcache hit rates?
A small status script calling opcache_get_status() shows hits and memory use. Remove it after checking.
Does OPcache help WP-CLI or cron?
CLI runs usually do not keep OPcache between runs, so the benefit there is small; web requests benefit most.
Will changing PHP version clear OPcache?
Yes. Switching version restarts PHP processes, which starts with an empty cache.
