buy
How To Configure PHP Opcache INI

Overview

This guide will show you how to configure and optimize PHP Opcache settings.

Opcache significantly enhances the performance of PHP-based applications by storing precompiled script bytecode in the server's shared memory. By utilizing a dedicated opcache.ini file, you can maintain a modular configuration that remains unaffected by global system updates.

Note:
We are going to show you example with php81, you can refer the following PHP names to load extensions for any other PHP's:
php56, php70, php71, php72, php73, php74, php80, php81, php82, php83,php84,php85

Steps:

Create a new opcache.ini file at /usr/local/apps/php81/etc/php.d/ 

You can create and edit this file using the following command:

nano /usr/local/apps/php81/etc/php.d/opcache.ini

Inside the file, add the PHP directives you wish to modify. For example:

; Enable Opcache
opcache.enable=1
opcache.enable_cli=1

; Memory Management
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=10000

; Validation Settings
opcache.revalidate_freq=2
opcache.validate_timestamps=1
Note:
Ensure your server has enough free RAM before increasing opcache.memory_consumption, as this memory is permanently allocated to the PHP process.

Once you have saved the file, you must restart the PHP-FPM service for the changes to take effect.

Execute the following command:

/usr/local/apps/php81/bin/fpmctl restart

You can verify that your settings have been applied correctly by running the following command in your terminal:

/usr/local/apps/php81/bin/php -i | grep opcache

That's it! Your custom PHP settings are now loaded for PHP 8.1 ,similarly you can load in other PHP's, just replace the php softname which is already mentioned above.

    Was this page helpful?
    Newsletter Subscription
    Subscribing you to the mailing list