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

Plesk服务器PHP版本不一致问题及升级至PHP 8.X并更新Zend OPcache的求助

Plesk服务器PHP版本不一致问题及升级至PHP 8.X并更新Zend OPcache的求助

Hey there, let's sort out this tricky PHP version mismatch on your Plesk server together! I totally get how frustrating it is when your website says one PHP version is running, but the command line throws a conflicting error. Let's break down the solution step by step:

问题根源

First, let's clarify what's happening here: your website uses the PHP version managed by Plesk (you confirmed it's 8.2, running via PHP-FPM/FCGI), but your system's command line (CLI) is still stuck on Ubuntu's default PHP 7.2. Plesk keeps website PHP versions separate from the system CLI PHP by default, which is why you're seeing this split behavior.

解决步骤

1. 确认Plesk中PHP 8.2已正确安装

  • Log into your Plesk admin panel, go to Tools & Settings > PHP Settings.
  • Look for the PHP 8.2 entry—make sure it's marked as "Installed". If it's not, you can click "Install" to add it directly here.

2. 找到Plesk管理的PHP 8.2 CLI路径

Plesk stores its PHP binaries in a dedicated directory. Verify the version of this CLI by running:

/opt/plesk/php/8.2/bin/php -v

This should output PHP 8.2's details, including the matching Zend OPcache version for 8.2.

3. 临时执行Artisan/Composer命令(用正确的PHP版本)

If you need to run commands right away, use the full path to Plesk's PHP 8.2 CLI:

  • For Composer:
    /opt/plesk/php/8.2/bin/php /usr/bin/composer update
    
    (If your Composer is installed elsewhere, replace /usr/bin/composer with your actual Composer path.)
  • For Laravel migrations:
    /opt/plesk/php/8.2/bin/php artisan migrate
    

4. 永久设置系统默认CLI PHP为8.2

To make PHP 8.2 the default for all CLI commands, use the update-alternatives tool:

  1. First, check existing PHP alternatives:
    update-alternatives --list php
    
  2. If PHP 8.2 isn't listed, add it to the alternatives:
    update-alternatives --install /usr/bin/php php /opt/plesk/php/8.2/bin/php 100
    
    The 100 sets a priority—higher numbers mean it's more likely to be selected as the default.
  3. Now select PHP 8.2 as the default:
    update-alternatives --config php
    
    You'll see a list of available PHP versions—enter the number next to PHP 8.2 and hit enter.
  4. Verify the change:
    php -v
    
    This should now show PHP 8.2 as the active CLI version.

5. 更新并启用Zend OPcache for PHP 8.2

Since your old OPcache was tied to PHP 7.2, we need to ensure the correct OPcache is enabled for PHP 8.2:

  • In Plesk, go back to Tools & Settings > PHP Settings > select PHP 8.2 > click Settings.
  • Under PHP extensions, find opcache and make sure it's checked (enabled).
  • If you need to tweak OPcache settings, edit the config file at /opt/plesk/php/8.2/etc/php.d/opcache.ini, then restart the PHP-FPM service for changes to take effect:
    systemctl restart plesk-php82-fpm
    

额外注意事项

  • Double-check that all your websites in Plesk are set to use PHP 8.2: Go to each website's Hosting Settings > PHP version and select 8.2.
  • Clear Composer's cache after switching PHP versions to avoid outdated dependency checks:
    php /usr/bin/composer clear-cache
    

备注:内容来源于stack exchange,提问作者Markus Blubb

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.21 09:35:30