在 Ubuntu 上查看 Apache2(apache2 服务)状态,常用方法如下:
systemctl status apache2
说明:
q 退出启动 / 停止 / 重启:
sudo systemctl start apache2
sudo systemctl stop apache2
sudo systemctl restart apache2
设置开机自启:
sudo systemctl enable apache2
sudo service apache2 status
启动 / 停止:
sudo service apache2 start
sudo service apache2 stop
sudo service apache2 restart
ps aux | grep apache2
或
pgrep -a apache2
sudo netstat -tlnp | grep apache2
# 或
sudo ss -tlnp | grep apache2
通常应看到 :80 或 :443
sudo tail -f /var/log/apache2/error.log
sudo tail -f /var/log/apache2/access.log
sudo apache2ctl configtest
输出 Syntax OK 表示配置无误。
systemctl is-active apache2
输出:
active → 正在运行inactive → 未运行如果你是想 通过浏览器确认 或 排查无法访问的问题,也可以告诉我具体现象。