温馨提示×

apache在centos如何更新

小樊
44
2026-10-14 18:12:20
栏目: 智能运维

在 CentOS 上更新 Apache(通常包名为 httpd)一般通过系统包管理器完成。下面分情况说明。


一、使用 yum / dnf 更新(推荐,适用于系统自带 Apache)

CentOS 7(使用 yum)

sudo yum update httpd

CentOS 8 / Stream(使用 dnf)

sudo dnf update httpd

更新完成后重启 Apache:

sudo systemctl restart httpd

查看版本:

httpd -v

二、更新所有系统软件(含 Apache)

如果你希望连系统一起更新:

sudo yum update      # CentOS 7
sudo dnf update      # CentOS 8 / Stream

三、确认 Apache 安装来源

有时 Apache 是通过 源码 或 第三方仓库(如 REMI、Software Collections) 安装的。

查看安装来源:

rpm -qi httpd

如果是第三方仓库(如 mod_ssl 来自 remi):

sudo yum update --enablerepo=remi

四、源码安装的 Apache 如何更新

如果当初是 ./configure && make && make install 安装的:

  1. 下载新版本源码
    https://httpd.apache.org/download.cgi

  2. 编译安装(注意备份配置):

./configure --prefix=/usr/local/apache2
make
make install
  1. 重启服务(依你自己的启动方式):
apachectl restart

五、更新后常见问题

  • 配置文件不兼容:查看错误日志
    journalctl -xe
    
  • 模块缺失:检查 httpd -M
  • SELinux 拦截:
    sudo setsebool -P httpd_can_network_connect 1
    

如果你能告诉我:

  • CentOS 具体版本(7 / 8 / Stream)
  • Apache 是 yum 安装还是源码安装

我可以给你更精确的命令。

0 踩