- 备份repo
shell
mkdir -p /etc/yum.repos.d/backup
mv /etc/yum.repos.d/CentOS-[^B]*.repo /etc/yum.repos.d/backup/ 2>/dev/null || true
- 下载阿里云镜像
shell
sudo wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
- 更新yum
shell
yum clean all
yum makecache
#或者直接
yum update
- 以安装remi的PHP8.1为例
shell
wget https://mirrors.aliyun.com/remi/enterprise/remi-release-7.rpm
rpm -Uvh remi-release-7.rpm
# 或者直接
yum install -y https://mirrors.aliyun.com/remi/enterprise/remi-release-7.rpm
# 查看是否已经安装
ls /etc/yum.repos.d/
backup docker-ce.repo epel.repo.rpmnew remi-modular.repo remi-php70.repo remi-php72.repo remi-php74.repo remi-php81.repo remi-php83.repo remi-safe.repo
CentOS-Base.repo epel.repo epel-testing.repo remi-php54.repo remi-php71.repo remi-php73.repo remi-php80.repo remi-php82.repo remi.repo
- 安装PHP8.1
shell
yum clean all
yum makecache
#或者直接
yum update
sudo yum install -y php81 php81-php-cli php81-php-fpm php81-php-common php81-php-mysqlnd php81-php-zip php81-php-devel php81-php-gd php81-php-mbstring php81-php-curl php81-php-xml php81-php-pear php81-php-bcmath php81-php-json php81-php-opcache php81-php-redis php81-php-memcached
# 查看PHP是否安装成功
php81 -v
PHP 8.1.29 (cli) (built: Jun 5 2024 05:51:57) (NTS gcc x86_64)
Copyright (c) The PHP Group
Zend Engine v4.1.29, Copyright (c) Zend Technologies
with Zend OPcache v8.1.29, Copyright (c), by Zend Technologies
如果出现以下错误
安装remi-release时出现错误
rpm -Uvh remi-release-7.rpm
warning: remi-release-7.rpm: Header V4 DSA/SHA1 Signature, key ID 00f97f56: NOKEY
error: Failed dependencies:
epel-release = 7 is needed by remi-release-7.9-6.el7.remi.noarch
shell
# 下载 epel repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
# 安装 epel-release
yum install epel-release
# 再次执行
rpm -Uvh remi-release-7.rpm
warning: remi-release-7.rpm: Header V4 DSA/SHA1 Signature, key ID 00f97f56: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:remi-release-7.9-6.el7.remi ################################# [100%]
多版本 composer
shell
curl -sS https://getcomposer.org/installer | /usr/bin/php81 -- --install-dir=/usr/local/bin --filename=composer8
mv /usr/local/bin/composer8 /usr/local/bin/composer8.phar
# 根据版本调整
echo -e '#!/bin/bash\n/usr/bin/php81 /usr/local/bin/composer8.phar "$@"' > /usr/local/bin/composer8
chmod +x /usr/local/bin/composer8