在 CentOS 上升级 Apache(httpd)主要有两种方式:通过系统包管理器升级(推荐) 和 通过源码编译升级。下面分别说明,并给出常见场景的操作步骤。
httpd -v
yum update httpd -y
升级完成后重启:
systemctl restart httpd
CentOS 8 默认使用 dnf:
dnf update httpd -y
systemctl restart httpd
httpd -v
CentOS 官方仓库中的 Apache 版本通常较旧,如果需要较新的 Apache 2.4 版本,可以使用 Software Collections (SCL) 或 Remi 仓库。
# CentOS 7
yum install epel-release -y
yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm -y
# CentOS 8
dnf install epel-release -y
dnf install http://rpms.remirepo.net/enterprise/remi-release-8.rpm -y
yum list available | grep httpd
yum update httpd --enablerepo=remi -y
或指定版本:
yum install httpd -y --enablerepo=remi
适合需要特定版本或自定义模块的情况。
yum groupinstall "Development Tools" -y
yum install openssl-devel pcre-devel expat-devel -y
wget https://downloads.apache.org/httpd/httpd-2.4.58.tar.gz
tar -zxvf httpd-2.4.58.tar.gz
cd httpd-2.4.58
./configure --prefix=/usr/local/apache \
--enable-so \
--enable-ssl \
--with-mpm=prefork
make
make install
⚠️ 注意:源码安装不会自动创建 systemd 服务,需要手动配置。
cp -r /etc/httpd /etc/httpd.bak
httpd -t
httpd -M
systemctl status httpd
curl -I http://localhost
| CentOS 版本 | 推荐方式 |
|---|---|
| CentOS 7 | yum + Remi |
| CentOS 8 | dnf + Remi |
| CentOS Stream | dnf + Remi |
| 特殊需求 | 源码编译 |
如果你愿意,可以告诉我:
cat /etc/centos-release)我可以给你一套完全适配你服务器的升级方案 ✅