Home > Backend Development > PHP Tutorial > How to install and enable PHP Opcache on CentOS

How to install and enable PHP Opcache on CentOS

WBOY
Release: 2024-03-06 08:38:02
Original
715 people have browsed it

如何在CentOS上安装和启用PHP Opcache

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

  1. Use SSH to connect to the CentOS server and log in as the root user.
  2. Install the PHP Opcache extension using the following command:

    yum install php-opcache
    Copy after login
  3. After the installation is complete, reload the PHP-FPM service for the changes to take effect:

    systemctl reload php-fpm
    Copy after login
    Copy after login

Step 2: Configure PHP Opcache

  1. 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
    Copy after login
  2. 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
    Copy after login
  3. Save and exit the configuration file , and then reload the PHP-FPM service:

    systemctl reload php-fpm
    Copy after login
    Copy after login

Step three: Verify whether PHP Opcache is enabled

  1. Create a file containing the phpinfo() function PHP file, such as info.php:

    <?php
     phpinfo();
    ?>
    Copy after login
  2. Place the info.php file into your website document directory, such as /var/www/html/.
  3. Enter your domain name/info.php in the browser, check whether there is information about the Opcache module in the PHP information page, and confirm that Opcache has been successfully enabled.

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template