在 CentOS 上重启 Apache(httpd) 服务,常用方法如下(适用于 CentOS 7/8/Stream,也兼容部分旧版本):
systemctl(推荐,CentOS 7 及以上)sudo systemctl restart httpd
查看状态:
sudo systemctl status httpd
设置开机自启(如未设置):
sudo systemctl enable httpd
service(旧版本 CentOS 6)sudo service httpd restart
sudo systemctl reload httpd
或
sudo service httpd reload
✅ reload:重新加载配置文件,不中断正在处理的请求
✅ restart:完全停止再启动服务
在重启前,建议先检查配置是否正确:
sudo httpd -t
或:
sudo apachectl configtest
sudo yum install httpd
sudo netstat -tulnp | grep :80
sudo tail -f /var/log/httpd/error_log
| 操作 | 命令 |
|---|---|
| 重启 | systemctl restart httpd |
| 启动 | systemctl start httpd |
| 停止 | systemctl stop httpd |
| 状态 | systemctl status httpd |
| 重载配置 | systemctl reload httpd |
如果你使用的是 CentOS 6 / Rocky / Alma / Ubuntu,或 Apache 配置虚拟主机,可以告诉我,我再具体说明。