在 Debian 上调试 LAMP(Linux + Apache + MySQL/MariaDB + PHP)环境,通常需要分层排查:系统 → Apache → PHP → 数据库。下面给你一套实用调试流程。
systemctl status apache2
systemctl status mariadb # 或 mysql
启动/重启:
systemctl start apache2
systemctl restart apache2
tail -f /var/log/apache2/error.log
常见错误:
Permission denied → 文件/目录权限问题DocumentRoot must be a directory → 路径错误apache2ctl configtest
确认站点已启用:
ls /etc/apache2/sites-enabled/
测试配置文件:
apache2ctl -S
php -v
ls /etc/apache2/mods-enabled/ | grep php
如未启用:
a2enmod php8.2 # 根据实际版本
systemctl restart apache2
创建测试文件:
echo "<?php phpinfo(); ?>" > /var/www/html/info.php
浏览器访问:
http://服务器IP/info.php
如果看到源码 → PHP 未解析
编辑:
/etc/php/8.2/apache2/php.ini
display_errors = On
error_reporting = E_ALL
重启 Apache。
mysql -u root -p
若无法登录:
systemctl status mariadb
journalctl -u mariadb
<?php
$conn = new mysqli("localhost", "user", "pass", "db");
if ($conn->connect_error) {
die("连接失败: " . $conn->connect_error);
}
echo "数据库连接成功";
?>
chown -R www-data:www-data /var/www/html
chmod -R 755 /var/www/html
Debian 一般不用 SELinux,但确认:
getenforce
ss -tunlp | grep ':80'
ufw status
允许 HTTP:
ufw allow 80
如果你愿意,可以告诉我:
我可以直接帮你定位问题。