温馨提示×

centos如何重启apache

小樊
47
2026-09-08 23:59:33
栏目: 智能运维

在 CentOS 中重启 Apache(通常服务名为 httpd)可以使用以下命令:

1. 使用 systemctl(CentOS 7 及以上推荐)

sudo systemctl restart httpd

其他常用操作:

sudo systemctl start httpd     # 启动
sudo systemctl stop httpd      # 停止
sudo systemctl status httpd    # 查看状态
sudo systemctl reload httpd    # 平滑重载配置(不中断服务)

2. 使用 service 命令(兼容旧版本)

sudo service httpd restart

3. CentOS 6 及更早版本

sudo /etc/init.d/httpd restart

说明

  • CentOS 中 Apache 的服务名是 httpd,不是 apache2(apache2 是 Ubuntu/Debian 的叫法)
  • 如果提示权限不足,请在命令前加 sudo 或使用 root 用户
  • 重启前可先测试配置文件是否正确:
    sudo apachectl configtest
    

如你安装的是其他集成环境(如宝塔、LNMP、XAMPP),重启方式会不同,可以告诉我具体环境。

0