要查看 Apache(httpd)运行状态,不同系统方法略有差异,以下是常见方式汇总。
适用于 CentOS 7+ / RHEL 7+ / Ubuntu 16.04+ / Debian 8+。
systemctl status httpd # CentOS / RHEL
systemctl status apache2 # Ubuntu / Debian
✅ 可看到:
适用于 CentOS 6 / RHEL 6 / 老版本 Ubuntu/Debian。
service httpd status
# 或
service apache2 status
ps -ef | grep httpd
# 或
ps -ef | grep apache2
或:
pgrep -a httpd
pgrep -a apache2
ss -lntp | grep :80
# 或
netstat -lntp | grep :80
常见端口:
httpd -t # CentOS / RHEL
apache2ctl -t # Ubuntu / Debian
✅ 返回 Syntax OK 表示配置无误。
httpd -v
# 或
apache2 -v
# CentOS / RHEL
journalctl -u httpd
# Ubuntu / Debian
journalctl -u apache2
或查看错误日志:
tail -f /var/log/httpd/error_log
tail -f /var/log/apache2/error.log
curl http://localhost
或浏览器访问服务器 IP。
| 状态 | 说明 |
|---|---|
| active (running) | 正常运行 |
| inactive (dead) | 未运行 |
| failed | 启动失败(需查看日志) |
systemctl is-active httpd && echo "Apache is running" || echo "Apache is NOT running"
如果你愿意,可以告诉我:
我可以帮你精准定位问题。