You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

CentOS 7下PHP 7.0的Opcache浏览器端启用问题求助

Fixing Zend Opcache for PHP 7.0 (Web Server) on CentOS 7

Hey there, let's get this Opcache issue sorted out—no DevOps expertise required, we'll take it slow and steady! The root of your problem is that your CLI PHP (7.1) and web server PHP (7.0) are totally separate installations with their own config files, so the Opcache setup you did for CLI doesn't apply to the browser-facing PHP. Here's how to fix it:

Step 1: Locate PHP 7.0's Configuration Files

First, we need to find where PHP 7.0 (the one Nginx uses, probably via PHP-FPM) stores its configs:

  • Run this command to confirm PHP 7.0-FPM's version and config path:
    php-fpm7.0 -t
    
    Look for lines like Configuration file: /etc/php-fpm.conf and Loaded configuration file: /etc/php.ini (this will be the PHP 7.0-specific php.ini).
  • If you can't find it that way, search for PHP 7.0's php.ini directly:
    find /etc -name "php.ini" | grep 7.0
    

Step 2: Enable Opcache in PHP 7.0's Config

Open the PHP 7.0 php.ini file (or the dedicated Opcache config, often in /etc/php.d/10-opcache.ini for CentOS) with a text editor like nano:

nano /etc/php.ini

Add or update these lines to enable Opcache (adjust values if needed, but these are safe defaults):

# Load the Opcache extension (make sure the path matches your system!)
zend_extension=opcache.so

# Enable Opcache for the web server
opcache.enable=1

# Keep this disabled for CLI (since you already set up 7.1 CLI separately)
opcache.enable_cli=0

# Basic performance settings
opcache.memory_consumption=128
opcache.max_accelerated_files=10000
opcache.revalidate_freq=2

Pro tip: If you're not sure where opcache.so is for PHP 7.0, run this command to find it:

find /usr/lib64/php/modules -name opcache.so | grep 7.0

Replace the path in zend_extension with the result.

Step 3: Restart Services to Apply Changes

After saving the config, restart PHP-FPM 7.0 and Nginx to make the changes take effect:

systemctl restart php-fpm7.0
systemctl restart nginx

Step 4: Verify Opcache is Working

To confirm Opcache is enabled for the web server:

  1. Create a file named phpinfo.php in your Nginx website's root directory (usually /usr/share/nginx/html/) with this content:
    <?php phpinfo(); ?>
    
  2. Access this file via your browser (e.g., http://your-vps-ip/phpinfo.php).
  3. Use your browser's search function to look for Zend OPcache—you should see opcache.enable set to On.

That's it! The key here was realizing that CLI and web PHP are separate entities with their own configs. Let me know if you hit any snags along the way.

内容的提问来源于stack exchange,提问作者Joe Remix

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 05:07:02