21+ years in hosting · Jaipur, India · INR billing with 18% GST · 24/7 email support
Blog · WebJi® India

Enable PHP OPcache

Quick answer

Enable PHP OPcache by setting opcache.enable=1 in the php.ini your website actually loads, then restarting PHP-FPM, Apache or the LiteSpeed PHP handler. In cPanel that is MultiPHP INI Editor. ini_set() cannot switch it on. Confirm with a one-line phpinfo file showing Zend OPcache enabled, then delete that file.

A step-by-step guide for site owners on cPanel shared hosting and Linux VPS servers who want PHP to stop recompiling every file on every request.

✓ In business since 2005
✓ INR + GST billing
✓ 24/7 Email Support — avg reply < 60 min
GuideWebJi®
knowledge
Read time
5 min
Sections
7
Updated
14 Nov 2026
Written by
WebJi® team

What does PHP OPcache actually cache?

PHP OPcache stores the compiled bytecode of each PHP file in shared memory, so repeat requests skip parsing and compiling the source. It does not store finished HTML, images or MySQL query results. Those belong to a page cache, a CDN or an object cache such as Redis.

The cache belongs to the PHP workers of one PHP version on the server, not to the visitor’s browser. It is switched on in php.ini with opcache.enable, never through a WordPress plugin, and the PHP manual (read 30 October 2026) gives that switch a default of 1.

  • Scope: one cache per PHP version and pool; two sites on PHP 8.2 and 8.3 have separate caches.
  • Runtime limit: ini_set('opcache.enable', 1) cannot turn it on. A script can only turn it off, and trying to enable it raises a warning.
  • Command line: CLI PHP (wp-cli, artisan, cron scripts) is excluded unless opcache.enable_cli=1, which only the main php.ini can set.

How do you check whether OPcache is on for your website?

Read the value through the web server, with a one-line phpinfo file in the site’s document root, because the shell often reports a different configuration. Running php -i over SSH loads the CLI ini, where opcache.enable_cli defaults to 0, so “Off” there says nothing about the website.

<?php phpinfo();

Save that as info.php, open it in the browser and search the page for “Zend OPcache”. The site uses the cache when three lines agree: the Zend OPcache block exists, opcache.enable reads On, and Opcode Caching says Up and Running. The file exposes server paths and versions, so delete it the same day.

Note the “Loaded Configuration File” line near the top of phpinfo. That is the ini the site really reads, and it is the file you edit on a VPS.

How to enable PHP OPcache in cPanel

In cPanel the switch lives in MultiPHP INI Editor under Software, set per domain. On WebJi® cPanel hosting you reach the panel from the client area, which is separate from the invoice pages. Changing the PHP version alone does not change opcache.enable.

  1. Log in to cPanel and open Software, then MultiPHP INI Editor.
  2. Select the domain. If opcache.enable is not in the Basic Mode list, switch to Editor Mode.
  3. Set opcache.enable to 1, or add the line opcache.enable=1 if it is absent.
  4. Leave opcache.memory_consumption at 128 for now. The manual minimum is 8.
  5. Save, reload info.php and confirm On. Delete the file.

If the value stays Off after saving, a php.ini or .user.ini inside the site folder is overriding the editor; the same leftover file often pins an old memory_limit. The cPanel PHP version guide shows where those files hide. WebJi® cPanel accounts list PHP 8.1, 8.2 and 8.3 in MultiPHP Manager; email support@webji.services if an application needs a version outside that list.

How to enable PHP OPcache on a Linux VPS

Without cPanel, edit the ini that phpinfo names as Loaded Configuration File, make sure the extension is loaded, and restart only the PHP service that serves the site. Root access for this is the practical reason sites move from shared plans to a Linux VPS.

# Ubuntu / Debian, PHP 8.3 under PHP-FPM
php --ini                                  # CLI view only; useful to see the conf.d layout
sudo apt install php8.3-opcache            # only if the module is missing
sudo nano /etc/php/8.3/fpm/php.ini         # in the [opcache] section set: opcache.enable=1
sudo systemctl restart php8.3-fpm

# AlmaLinux / Rocky Linux
sudo dnf install php-opcache
sudo nano /etc/php.d/10-opcache.ini        # opcache.enable=1
sudo systemctl restart php-fpm

On Debian-family systems the line zend_extension=opcache.so sits in mods-available/opcache.ini and is linked into conf.d as 10-opcache.ini; if it is commented out, uncomment it. Apache with mod_php reads /etc/php/8.3/apache2/php.ini instead and needs systemctl restart apache2. The CLI file, /etc/php/8.3/cli/php.ini, is a third copy that a normal website never reads.

On LiteSpeed, PHP runs as lsphp, so restarting php-fpm changes nothing. Restart the LiteSpeed PHP handler for that version; the LiteSpeed vs Apache comparison explains how the two handle PHP processes.

Which OPcache settings matter, and what values should you use?

For one WordPress or Laravel site the manual defaults are sound; change memory or file limits only when the status numbers show the cache is short. Defaults below are from the PHP manual, read 30 October 2026.

Core OPcache directives, PHP manual defaults and practical advice
DirectiveDefaultAdvice
opcache.enable11 for the website. Cannot be turned on with ini_set().
opcache.enable_cli0Leave 0 unless CLI jobs must reuse the cache. Main php.ini only.
opcache.memory_consumption128 MB (minimum 8)128 suits one site. With JIT on, this segment also holds the JIT buffer.
opcache.interned_strings_buffer8 MBRaise only when interned-string free memory nears zero. Maximum 32767 MB on 64-bit since PHP 8.4; 4095 MB before.
opcache.max_accelerated_files10000PHP rounds up to the prime 16229. Allowed range 200 to 1000000.
opcache.validate_timestamps1Keep 1 while files change. At 0, edits wait for a reset or restart.
opcache.revalidate_freq2 seconds0 checks every request. Ignored when validate_timestamps is 0.
opcache.jitdisable (PHP 8.4+)Not needed for the opcode cache. Before 8.4 the default was tracing, with a 0 buffer; the buffer default is now 64 MB.

Keep opcache.save_comments=1: at 0 the docblocks disappear and code that reads annotations breaks. Remove any opcache.fast_shutdown line copied from an old tutorial; the directive was dropped in PHP 7.2.

Why do PHP file edits not show after OPcache is enabled?

Either OPcache has not rechecked the file’s timestamp yet, or an HTML page cache in front of PHP is still serving the old page. With validate_timestamps=1 PHP rechecks a file every revalidate_freq seconds, two by default. With it at 0, the old bytecode stays until opcache_reset(), opcache_invalidate() or a PHP restart.

Clearing one layer does not clear the other. LiteSpeed LSCache and WordPress page-cache plugins store finished HTML, so purge them separately; the guide to clearing WordPress cache lists where each layer lives. On shared cPanel you usually cannot restart the PHP pool, which is why validate_timestamps should stay at 1 there. If opcache_reset() is disabled on your account, email support@webji.services and ask for PHP to be recycled.

How do you know the OPcache memory is large enough?

Look at the OOM restarts and Free memory lines in the phpinfo OPcache block: a non-zero OOM count or free memory near zero means the cache is too small. Raise opcache.memory_consumption in steps, for example 128 to 192, and recheck after a day of normal traffic.

If phpinfo is not convenient, a short script prints the same counters, provided opcache.restrict_api does not block it:

<?php
$s = opcache_get_status(false);
echo 'enabled: ', var_export($s['opcache_enabled'], true), "\n";
echo 'free MB: ', round($s['memory_usage']['free_memory'] / 1048576, 1), "\n";
echo 'oom restarts: ', $s['opcache_statistics']['oom_restarts'], "\n";
echo 'cached scripts: ', $s['opcache_statistics']['num_cached_scripts'], "\n";

Expect a shorter PHP processing time, not a universal percentage. A page that waits on a slow MySQL query or a heavy hero image will not feel much faster; speeding up a WordPress website covers the other layers. Several sites on one server each add their own scripts, so a multi-site VPS usually needs more than the 128 MB default.

FAQ

Frequently asked questions

Is OPcache enabled by default on PHP 8?

The PHP manual default for opcache.enable is 1 on PHP 8, but the extension must be loaded and a host can set the value to 0 in the ini your domain uses. Check phpinfo for that specific domain instead of trusting the default.

Does OPcache replace a WordPress caching plugin?

No. OPcache saves the work of compiling PHP; a page-cache plugin or LSCache saves the work of running PHP and MySQL at all for anonymous visitors. The two stack well, and most fast WordPress sites run both.

Should I set opcache.validate_timestamps to 0 for speed?

Only on a server you control, where every deployment ends with a PHP-FPM reload or opcache_reset(). It saves a file-stat call per request, but forgotten reloads leave old code running. On shared hosting keep it at 1.

Is it safe to enable the OPcache JIT?

It is optional and separate from the opcode cache. Typical WordPress and Laravel requests are bound by database and I/O time, so JIT rarely changes response time. Turn it on only after measuring a CPU-heavy workload, and leave it off if an extension conflicts.

Why does wp-cli say OPcache is disabled when the site says enabled?

wp-cli runs command-line PHP, which reads the CLI ini and uses opcache.enable_cli, default 0. The website runs through PHP-FPM, LiteSpeed or Apache with its own ini. Both readings can be correct at the same time.

Directive defaults checked against the PHP manual on 30 October 2026 · Page checked 14 November 2026 · Reviewed by the WebJi® team, Jaipur.

WebJi® since 2005

Ready to get started with WebJi®?

Join 12,000+ businesses across India and overseas. INR pricing, 18% GST shown before payment and 24/7 email support in Hindi and English — average first reply under 60 minutes.