要测试 Apache2 是否正在运行,可以根据你使用的操作系统,选择以下几种常用方法(适用于大多数 Linux 发行版)。
systemctl status apache2
✅ 如果看到类似以下内容,说明 Apache2 正在运行:
Active: active (running) since ...
❌ 如果显示:
Active: inactive (dead)
说明 Apache2 没有运行。
启动 Apache2:
sudo systemctl start apache2
设置开机自启:
sudo systemctl enable apache2
sudo service apache2 status
或:
sudo /etc/init.d/apache2 status
ps aux | grep apache2
如果看到多个 apache2 进程,通常说明它正在运行。
ss -tlnp | grep :80
或:
netstat -tlnp | grep :80
✅ 看到 LISTEN 状态说明 Apache 正在监听 HTTP 端口。
在浏览器中访问:
http://localhost
或服务器 IP:
http://服务器IP
✅ 看到 Apache2 默认欢迎页面 说明运行正常。
curl http://localhost
或:
curl http://127.0.0.1
如果返回 HTML 内容,说明 Apache2 正常运行。
sudo apache2ctl configtest
✅ 返回:
Syntax OK
说明配置文件没有语法错误。
查看日志:
sudo journalctl -xe
或:
sudo tail -n 50 /var/log/apache2/error.log
✅ 推荐命令:
systemctl status apache2
如果你告诉我你的系统版本(如 Ubuntu 20.04 / Debian / CentOS),我可以给你更精确的命令。