下面按「从最常见问题到系统化排查」给你一个 Debian + Apache2 调试手册,适合新手到进阶。
systemctl status apache2
或
service apache2 status
启动 / 停止 / 重启:
sudo systemctl start apache2
sudo systemctl stop apache2
sudo systemctl restart apache2
sudo apache2ctl configtest
或
sudo apache2 -t
常见错误:
DocumentRoot 路径不存在VirtualHost 端口冲突sudo tail -f /var/log/apache2/error.log
sudo tail -f /var/log/apache2/access.log
常见报错含义:
403 Forbidden → 权限或 Directory 配置问题404 Not Found → 路径或 DocumentRoot 错500 Internal Error → PHP / .htaccess / 脚本错误ls /etc/apache2/sites-enabled/
启用 / 禁用站点:
sudo a2ensite example.conf
sudo a2dissite example.conf
sudo systemctl reload apache2
测试虚拟主机:
curl -I http://localhost
curl -I http://yourdomain.com
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>
apache2ctl -M
启用模块(如 rewrite):
sudo a2enmod rewrite
sudo systemctl restart apache2
<?php phpinfo(); ?>
若直接下载文件:
sudo a2enmod php8.2 # 视版本而定
sudo systemctl restart apache2
sudo ss -tlnp | grep apache
sudo ufw allow 80
sudo ufw allow 443
在站点配置或 .htaccess:
LogLevel alert rewrite:trace3
sudo apache2ctl -S
configtest 通过error.log 无报错a2ensitewww-data如果你愿意,可以 直接贴出:
error.log 片段我可以帮你精确定位问题。