服务器升级php8.2报错

目前我们的服务器php 版本是8.1.32 但是现在项目需求需要升级的php8.2 然后我们执行命令

dnf install php8.2 

报错了,让我们来看看是什么错误

MySQL 8.0 Community Server                          8.4 kB/s | 2.6 kB     00:00    
MySQL Connectors Community                          8.1 kB/s | 2.6 kB     00:00    
MySQL Tools Community                               8.1 kB/s | 2.6 kB     00:00    
Remi's Modular repository for Enterprise Linux 9 -  4.5 kB/s | 3.5 kB     00:00    
Remi's Modular repository for Enterprise Linux 9 -  281 kB/s | 800 kB     00:02    
Safe Remi's RPM repository for Enterprise Linux 9 - 3.0 kB/s | 3.0 kB     00:01    
Safe Remi's RPM repository for Enterprise Linux 9 -  59 kB/s | 1.2 MB     00:20    
No match for argument: php8.2
Error: Unable to find a match: php8.2

我们的系统环境(Enterprise Linux 9 系列,如 RHEL/CentOS/Rocky/AlmaLinux),PHP 8.2 需要通过 Remi 仓库正确配置才能安装。以下是完整的解决方案:

解决方案:在 EL9 系统安装 PHP 8.2

  1. 安装必要工具和仓库
# 安装 EPEL 仓库(基础依赖)
sudo dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm

# 安装 Remi 仓库(PHP 专用源)
sudo dnf install https://rpms.remirepo.net/enterprise/remi-release-9.rpm

# 清理缓存
sudo dnf clean all
sudo dnf makecache
  1. 启用 PHP 8.2 模块
# 查看可用的 PHP 模块流
sudo dnf module list php

# 启用 PHP 8.2 模块流
sudo dnf module enable php:remi-8.2 -y

到这里又报错了

Last metadata expiration check: 0:04:32 ago on 2025年04月06日 星期日 18时35分32秒.
Dependencies resolved.
The operation would result in switching of module 'php' stream 'remi-8.1' to stream 'remi-8.2'
Error: It is not possible to switch enabled streams of a module unless explicitly enabled via configuration option module_stream_switch.
It is recommended to rather remove all installed content from the module, and reset the module using 'dnf module reset <module_name>' command. After you reset the module, you can install the other stream.

根据错误提示,需先重置 PHP 模块后再切换版本。以下是完整操作步骤:

解决方案:安全切换 PHP 8.1 → 8.2

  1. 重置现有 PHP 模块
sudo dnf module reset php -y
# 此操作会解除当前 PHP 8.1 的模块锁定,不会删除已安装的 PHP 包
  1. 启用 PHP 8.2 模块流
sudo dnf module enable php:remi-8.2 -y
  1. 执行 PHP 8.2 升级安装
sudo dnf install php php-cli php-common php-mysqlnd php-gd php-curl php-mbstring php-xml php-zip
  1. 验证操作结果
php -v

PHP 8.2.28 (cli) (built: Mar 11 2025 17:58:12) (NTS gcc x86_64)
Copyright (c) The PHP Group
Zend Engine v4.2.28, Copyright (c) Zend Technologies
with Zend OPcache v8.2.28, Copyright (c), by Zend Technologies

好了,我们的问题解决了。

luffy博客
Please login to comment
  • latest comments
  • Total 0 comments