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:
(If your Composer is installed elsewhere, replace/opt/plesk/php/8.2/bin/php /usr/bin/composer update/usr/bin/composerwith 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:
- First, check existing PHP alternatives:
update-alternatives --list php - If PHP 8.2 isn't listed, add it to the alternatives:
Theupdate-alternatives --install /usr/bin/php php /opt/plesk/php/8.2/bin/php 100100sets a priority—higher numbers mean it's more likely to be selected as the default. - Now select PHP 8.2 as the default:
You'll see a list of available PHP versions—enter the number next to PHP 8.2 and hit enter.update-alternatives --config php - Verify the change:
This should now show PHP 8.2 as the active CLI version.php -v
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
opcacheand 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

