centos 8.2 升级 php7.2 到 7.4

内容纲要

背景

我的 wordpress 运行在 php7.2 上,可以参考这篇文章 centos 8.2 安装 php 7.2.24

wordpress 已经持续提醒我升级 php 好久了,那么今天就来升级吧

先看下当前环境

uname -a
Linux VM-20-15-centos 4.18.0-305.3.1.el8.x86_64 #1 SMP Tue Jun 1 16:14:33 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

php -v
PHP 7.2.24 (cli) (built: Oct 22 2019 08:28:36) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies

这个环境和前面那篇安装文可能有点出入,因为我现在用的服务器已经从阿里云 ECS 迁移到腾讯云轻量服务器了

升级

在网上寻摸了一圈,根据教程,升级到 php7.4 需要先安装两个 yum 源

  • epel-release
  • remi-release

这一步就走了很多弯路,因为你在网上找的教程多半是下面这样的

yum install epel-release
yum install  http://rpms.remirepo.net/enterprise/remi-release-7.rpm

然后你会收获如下的 Error

Error:
 Problem: conflicting requests
  - nothing provides epel-release = 7 needed by remi-release-7.9-5.el7.remi.noarch

嗯,你安装了 epel 8,但是继续安装 remi 7 的时候,它需要 epel 7

接下来很简单,有 2 个解决方案

  • 删除 epel 8,重装 epel 7
  • 留着 epel 8,安装 remi 8

实际上两个我都试过了,先说安装 epel 7 的遭遇

epel 7

wget https://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/e/epel-release-7-14.noarch.rpm
yum install epel-release-7-14.noarch.rpm
yum install  http://rpms.remirepo.net/enterprise/remi-release-7.rpm

很顺利的,然后是如下的操作

yum install yum-utils -y
yum-config-manager --enable remi-php74
yum update

这个时候会收获 Error

Error:
 Problem 1: cannot install the best update candidate for package libidn2-2.2.0-1.el8.x86_64
  - nothing provides libunistring.so.0()(64bit) needed by libidn2-2.3.4-1.el7.x86_64
 Problem 2: package remi-release-7.9-5.el7.remi.noarch requires epel-release = 7, but none of the providers can be installed
  - cannot install both epel-release-8-11.el8.noarch and epel-release-7-14.noarch
  - cannot install both epel-release-7-14.noarch and epel-release-8-11.el8.noarch
  - cannot install the best update candidate for package remi-release-7.9-5.el7.remi.noarch
  - cannot install the best update candidate for package epel-release-7-14.noarch
 Problem 3: package python3-tracer-0.7.5-2.el8.noarch requires tracer-common = 0.7.5-2.el8, but none of the providers can be installed
  - cannot install both tracer-common-1.1-1.el7.noarch and tracer-common-0.7.5-2.el8.noarch
  - cannot install the best update candidate for package tracer-common-0.7.5-2.el8.noarch
  - cannot install the best update candidate for package python3-tracer-0.7.5-2.el8.noarch

看屏幕输出,貌似可以加个 –nobest 来强行安装,实际上的确可以,但是最后安装 php 会报错

yum install php php-mcrypt php-cli php-gd php-curl php-mysql php-ldap php-zip php-process php-ldap

Error

Invalid configuration value: failovermethod=priority in /etc/yum.repos.d/epel.repo; Configuration: OptionBinding with id "failovermethod" does not exist
Invalid configuration value: failovermethod=priority in /etc/yum.repos.d/epel.repo; Configuration: OptionBinding with id "failovermethod" does not exist
Invalid configuration value: failovermethod=priority in /etc/yum.repos.d/epel.repo; Configuration: OptionBinding with id "failovermethod" does not exist
Invalid configuration value: failovermethod=priority in /etc/yum.repos.d/epel-testing.repo; Configuration: OptionBinding with id "failovermethod" does not exist
Invalid configuration value: failovermethod=priority in /etc/yum.repos.d/epel-testing.repo; Configuration: OptionBinding with id "failovermethod" does not exist
Invalid configuration value: failovermethod=priority in /etc/yum.repos.d/epel-testing.repo; Configuration: OptionBinding with id "failovermethod" does not exist
CentOS Linux 8 - AppStream                    87  B/s |  38  B     00:00
Error: Failed to download metadata for repo 'appstream': Cannot prepare internal mirrorlist: No URLs in mirrorlist

经过一番查询,貌似可以用如下办法来解决

  • 修改 /etc/yum.repos.d/epel.repo, /etc/yum.repos.d/epel-testing.repo, 将 failovermethod 行注释

  • 执行如下命令

cd /etc/yum.repos.d/

sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*

sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*

yum makecache

最后你会沮丧的发现,还是没有办法成功安装 php7.4

epel 8

于是我又回头,决定在 epel 8 下进行安装

dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm

dnf install https://rpms.remirepo.net/enterprise/remi-release-8.rpm

这时又会遇到 Error

remi-release-8.rpm                                                                                                                                        26 kB/s |  32 kB     00:01
Error:
 Problem: conflicting requests
  - nothing provides (redhat-release >= 8.8 or centos-stream-release >= 8) needed by remi-release-8.8-1.el8.remi.noarch

这时可以如下解决

dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm

dnf -y install centos-release-stream

dnf install https://rpms.remirepo.net/enterprise/remi-release-8.rpm

这次不报错了,继续

dnf module list php

dnf module reset php

dnf module enable php:remi-7.4

dnf install php php-cli php-common

看看 php 版本

php -v

PHP 7.4.33 (cli) (built: Aug  1 2023 08:47:49) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies with Zend OPcache v7.4.33, Copyright (c), by Zend Technologies

大功告成,重启 php 即可

service php-fpm restart

参考文档

centos 8.2 升级 php7.2 到 7.4

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

Scroll to top
粤ICP备2020114259号 粤公网安备44030402004258