温馨提示×

Apache在CentOS如何重启

小樊
38
2026-07-20 09:09:00
栏目: 智能运维

CentOS 上重启 Apache(httpd) 服务,常用方法如下(取决于 CentOS 版本):


一、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

或:

sudo /etc/init.d/httpd restart

三、验证 Apache 是否运行

ps -ef | grep httpd

curl http://localhost

四、常见问题

❌ 提示 Unit httpd.service not found

说明 Apache 未安装,先安装:

sudo yum install httpd

❌ 端口被占用(如 80)

查看占用情况:

sudo netstat -tulnp | grep :80

五、快速总结

操作 命令
重启 systemctl restart httpd
启动 systemctl start httpd
停止 systemctl stop httpd
状态 systemctl status httpd

如果你告诉我 CentOS 具体版本是否使用宝塔 / Docker,我可以给你更精确的命令。

0