How to install and enable PHP Opcache on CentOS
PHP Opcache is an extension module for PHP that can improve the performance of PHP applications and reduce the load on the server. Installing and enabling PHP Opcache on CentOS is very simple, the specific steps and code examples are detailed below.
Step 1: Install the PHP Opcache extension
Install the PHP Opcache extension using the following command:
yum install php-opcache
After the installation is complete, reload the PHP-FPM service for the changes to take effect:
systemctl reload php-fpm
Step 2: Configure PHP Opcache
Open the PHP configuration file php.ini for editing, usually located in /etc/php.ini or /etc/php/ 7.x/php.ini, where 7.x represents your PHP version. Find the following line and uncomment it:
zend_extension=opcache.so
Add or modify the following configuration items to suit your needs:
[opcache] opcache.enable=1 opcache.enable_cli=1 opcache.memory_consumption=128 opcache.interned_strings_buffer=8 opcache.max_accelerated_files=4000 opcache.validate_timestamps=1 opcache.revalidate_freq=60 opcache.fast_shutdown=1
Save and exit the configuration file , and then reload the PHP-FPM service:
systemctl reload php-fpm
Step three: Verify whether PHP Opcache is enabled
Create a file containing the phpinfo() function PHP file, such as info.php:
<?php phpinfo(); ?>
At this point, you have successfully installed and enabled the PHP Opcache extension on CentOS. By optimizing the caching of PHP code, you can significantly improve your website performance and loading speed. Hope the above steps and code examples help you!
The above is the detailed content of How to install and enable PHP Opcache on CentOS. For more information, please follow other related articles on the PHP Chinese website!