在CentOS系統中,要啟用PHP的OPcache擴展,請按照以下步驟操作:
sudo yum install php
sudo yum install php-opcache
對于其他PHP版本,請將php-opcache替換為相應的軟件包名稱,例如php72-php-opcache。
/etc/php.ini文件,添加以下行:[opcache]
zend_extension=opcache.so
opcache.enable=1
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.revalidate_freq=60
這些設置將啟用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配置的詳細信息。