在 Debian 系统中,Apache2 通常使用 systemd 来管理。下面是常见的启动、停止、重启和设置开机自启的方法。
sudo systemctl start apache2
sudo systemctl enable apache2
sudo systemctl status apache2
如果看到 active (running) 说明已成功启动。
重启:
sudo systemctl restart apache2
停止:
sudo systemctl stop apache2
重新加载配置(不中断服务):
sudo systemctl reload apache2
如果提示 Unit apache2.service not found,说明可能未安装:
sudo apt update
sudo apt install apache2
如果启用了防火墙(如 ufw),需允许 HTTP:
sudo ufw allow 80
HTTPS(可选):
sudo ufw allow 443
浏览器访问:
http://localhost
或服务器 IP,看到 Apache 默认页面即成功。
如果你是在 Docker / WSL / 旧版 Debian(sysvinit) 环境,启动方式会略有不同,可以告诉我你的具体环境,我可以进一步说明。