温馨提示×

CentOS怎么重启Apache服务

小樊
41
2026-08-18 21:36:48
栏目: 智能运维

CentOS 上重启 Apache 服务,常用命令取决于你的 CentOS 版本以及 Apache 的服务名(通常是 httpd)。


一、CentOS 7 / 8 / 9(使用 systemd)

1️⃣ 重启 Apache

sudo systemctl restart httpd

2️⃣ 启动 / 停止 / 查看状态

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

3️⃣ 设置开机自启

sudo systemctl enable httpd

二、CentOS 6 或更早版本(使用 service)

sudo service httpd restart

三、确认 Apache 是否安装成功

httpd -v

apachectl -v

四、常见问题排查

✅ 查看端口是否监听

ss -lntp | grep 80

✅ 查看错误日志

sudo tail -f /var/log/httpd/error_log

✅ 配置文件检查

sudo apachectl configtest

五、如果是通过宝塔 / LNMP 安装的 Apache

  • 宝塔:
bt restart
  • LNMP:
lnmp restart

如果你不确定 CentOS 版本Apache 安装方式,可以把下面命令的输出发给我:

cat /etc/os-release
systemctl status httpd

0