PHP re-reads and re-compiles every script on every request unless you tell it not to. OPcache is that instruction: it keeps compiled bytecode in shared memory and routinely cuts response times by half or more. It is also the reason your freshly deployed code sometimes "does nothing" for minutes at a time. Both behaviors come from the same few settings.
Enable it
OPcache ships with PHP but is often disabled by default. In your PHP-FPM php.ini (or a file in conf.d, such as /etc/php/8.3/fpm/conf.d/10-opcache.ini):
zend_extension=opcache
opcache.enable=1
opcache.enable_cli=0
Restart PHP-FPM afterwards: sudo systemctl restart php8.3-fpm. Keep opcache.enable_cli=0 - caching CLI scripts wastes memory and helps nothing, because each CLI process is fresh anyway.
Size it for a real application
The defaults date from a much smaller era of PHP applications. A Laravel or Symfony app with vendor directories needs more:
opcache.memory_consumption=256
opcache.interned_strings_buffer=16
opcache.max_accelerated_files=20000
If the cache fills up, OPcache silently stops caching new files - your most-requested code paths may be the ones left out. Check usage before assuming it works (see the verification step below).
Why code changes stop showing up
By default OPcache checks file timestamps on every request (opcache.validate_timestamps=1, opcache.revalidate_freq=2 seconds), which is safe but wastes stat calls. The common production hardening is:
opcache.validate_timestamps=0
With timestamps off, OPcache never looks at the filesystem again. Deploy new code and the old bytecode keeps serving until you reset the cache. This is the moment developers think their deploy failed. The fix is to make cache invalidation part of the deploy:
# option 1: graceful, per deploy
php -r 'opcache_reset();' # only works with opcache.enable_cli=1 and clears the CLI cache, not FPM!
# option 2: the reliable one
sudo systemctl reload php8.3-fpm
A graceful reload (not restart) drops the cache without killing in-flight requests. If you prefer not to reload, expose opcache_reset() through a protected deploy-only route, or keep validate_timestamps=1 with a low revalidate_freq and accept the stat overhead.
Verify it is actually working
Do not trust the ini file - verify the running state:
php -v
# Zend Engine v4.x, Copyright (c) Zend Technologies
# with Zend OPcache v8.x, Copyright (c), by Zend Technologies
That only proves the extension loads in the CLI. For FPM, drop a temporary route or file calling opcache_get_status(false) and check opcache_enabled, memory_usage.used_memory against your limit, and opcache_statistics.num_cached_scripts. Delete the file when done. Tools like Laravel Pulse or a one-off opcache_get_status dump both work.
Laravel notes
OPcache caches PHP bytecode, not Laravel's own caches. config:cache, route:cache and compiled Blade views are separate and are rebuilt by their own artisan commands - you still need those in your deploy script alongside the FPM reload.
Summary
Enable OPcache in the FPM configuration, give it enough memory and file slots for your whole application including vendor, and decide explicitly how deploys invalidate it. With validate_timestamps=0 plus an FPM reload on deploy you get maximum performance with zero stale-code surprises.