在 CentOS 上“换 LAMP 版本”一般有几种常见场景,我先按最常见需求给你说明,你再看自己属于哪一种。
LAMP = Linux + Apache + MySQL/MariaDB + PHP
常见换版本情况:
yum install -y epel-release
yum install -y https://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum list available php* --enablerepo=remi-php74
yum install -y yum-utils
yum-config-manager --enable remi-php81
yum install -y php php-cli php-common php-mysqlnd php-fpm
systemctl restart httpd
systemctl restart php-fpm
✅ 查看版本:
php -v
CentOS 官方源 Apache 版本较旧(如 2.4.x),不建议手动编译。
yum install -y centos-release-scl
yum install -y httpd24
scl enable httpd24 bash
⚠️ 注意:SCL 版本是“并行运行”,不是完全替换系统 httpd。
yum remove mariadb mariadb-server
vi /etc/yum.repos.d/MariaDB.repo
内容:
[mariadb]
name = MariaDB
baseurl = https://mirrors.aliyun.com/mariadb/yum/10.6/centos7-amd64
gpgkey=https://mirrors.aliyun.com/mariadb/yum/RPM-GPG-KEY-MariaDB
gpgcheck=1
yum install -y MariaDB-server MariaDB-client
systemctl start mariadb
❗ 不要直接覆盖系统自带 PHP/MySQL
httpd 无法启动✅ 建议:
mysqldump -uroot -p --all-databases > all.sql
我可以直接给你一步一步的命令。