温馨提示×

centos中apache如何重启

小樊
48
2026-10-20 12:06:34
栏目: 智能运维

在 CentOS 中重启 Apache(通常服务名为 httpd)可以根据系统版本和初始化方式选择以下方法:

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

sudo systemctl restart httpd

其他常用命令:

sudo systemctl start httpd     # 启动
sudo systemctl stop httpd      # 停止
sudo systemctl status httpd    # 查看状态

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

sudo service httpd restart

3. 使用 apachectl(直接调用 Apache 控制脚本)

sudo apachectl restart

或先停止再启动:

sudo apachectl stop
sudo apachectl start

4. CentOS 6 及更早版本(SysVinit)

sudo /etc/init.d/httpd restart

注意事项

  • 如果提示 command not found 或 Failed to restart httpd.service: Unit httpd.service not found,说明可能未安装 Apache,可先安装:
    sudo yum install httpd
    
  • 修改配置后建议先测试配置是否正确:
    sudo apachectl configtest
    
    显示 Syntax OK 再重启。

如果你用的是 CentOS Stream 或 Apache 从源码编译安装,路径可能不同,可以告诉我你的系统版本和安装方式,我帮你具体看。

0 踩