OPcache is a PHP 8.4 extension that improves performance by caching the precompiled opcode of PHP scripts. This reduces the load and execution time of scripts, making your application faster and more efficient. Here’s how to set it up in PHP 8.4.

Step 1: Verify the Installation of OPcache in PHP
First, make sure OPcache is installed and enabled on your server. You can verify this by running the following command on the command line:
php -v
Step 2: Configure OPcache in PHP 8.4
Open your 10-opcache.ini file and add or modify the following lines to enable and configure OPcache:
nano /etc/php/8.4/cli/conf.d/10-opcache.ini
zend_extension=opcache.so
opcache.enable=1
opcache.enable_cli=1
opcache.jit_buffer_size=2048M
opcache.jit=1235
opcache.memory_consumption=2048
opcache.max_accelerated_files=50000
opcache.revalidate_freq=2
Recommended OPcache settings for 1 GB RAM
zend_extension=opcache.so
opcache.enable=1
opcache.enable_cli=1
opcache.memory_consumption=64
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.revalidate_freq=10
opcache.validate_timestamps=1
opcache.jit_buffer_size=16M
opcache.jit=tracing
opcache.fast_shutdown=1
Step 3: Restart the Web Server
After making the changes, restart your web server for the changes to take effect. If you’re using Apache, you can restart it with:
systemctl restart apache2
Step 4: Check the OPcache Settings in PHP 8.4
To make sure that OPcache is working correctly, you can run the following command:
php -i | grep opcache
Conclusion
Setting up OPcache is a crucial step in improving the performance of your PHP applications. By following these steps, you can ensure that your server is optimized and ready to handle more efficient workloads.