在 CentOS 系统中,要启用 PHP 的 OPcache 扩展,请按照以下步骤操作:
sudo yum install epel-release
sudo yum install https://rpms.remirepo.net/enterprise/remi-release-7.rpm
sudo yum-config-manager --enable remi-php7x
将 7x 替换为您需要的 PHP 版本,例如 7.2、7.3 或 7.4。
sudo yum update php\*
sudo yum install php-opcache
sudo systemctl restart httpd
如果您使用的是 Nginx 和 PHP-FPM,请运行:
sudo systemctl restart nginx
sudo systemctl restart php-fpm
info.php 的文件,放在您的 web 服务器根目录下,包含以下内容:<?php
phpinfo();
?>
在浏览器中访问此文件(例如:http://your_server_ip/info.php),然后搜索 “opcache”。如果已启用 OPcache,您将看到有关 OPcache 配置的详细信息。
info.php 文件。