下面按常见场景给你一份「Debian 上调试 Apache」的实用清单,从最基础到进阶,基本能覆盖 90% 的问题。
systemctl status apache2
或
service apache2 status
启动 / 重启 / 停止:
sudo systemctl start apache2
sudo systemctl restart apache2
sudo systemctl stop apache2
改完配置先检查语法:
sudo apache2ctl configtest
或
apache2 -t
✅ 输出 Syntax OK 才安全
/var/log/apache2/error.log
实时查看:
sudo tail -f /var/log/apache2/error.log
访问日志:
sudo tail -f /var/log/apache2/access.log
sudo ss -tulnp | grep apache
# 或
sudo netstat -tulnp | grep apache
默认端口:
如果端口被占用:
sudo lsof -i :80
ls /etc/apache2/sites-enabled/
apache2ctl -S
常见错误:
sudo chown -R www-data:www-data /var/www/html
sudo chmod -R 755 /var/www
<Directory /var/www/html>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
修改后:
sudo systemctl reload apache2
LogLevel alert trace8
或
LogLevel debug
重启 Apache 后看 error.log
⚠️ 生产环境不要长期开 debug
apache2ctl -M
sudo a2enmod rewrite
sudo a2enmod ssl
sudo systemctl restart apache2
sudo apt install libapache2-mod-php
sudo a2enmod php
sudo systemctl restart apache2
sudo ufw allow 80
sudo ufw allow 443
configtest 通过error.log 无致命错误如果你愿意,可以告诉我:
我可以直接帮你针对性排错。