调试 Debian 上的 LNMP(Linux + Nginx + MySQL/MariaDB + PHP) 通常要分层次来查。下面给你一套系统化调试思路 + 常用命令,基本能覆盖 90% 的问题。
lsb_release -a
uname -a
systemctl status nginx
systemctl status mariadb # 或 mysql
systemctl status php-fpm # 看版本,如 php8.2-fpm
如果没启动:
systemctl start nginx
systemctl start mariadb
systemctl start php8.2-fpm
设置开机自启:
systemctl enable nginx mariadb php8.2-fpm
nginx -t
tail -f /var/log/nginx/error.log
tail -f /var/log/nginx/access.log
| 现象 | 原因 |
|---|---|
| 502 Bad Gateway | PHP-FPM 没启动 / sock 路径错 |
| 403 Forbidden | 目录权限 / index 文件缺失 |
| 404 | root 路径配置错误 |
server {
listen 80;
server_name example.com;
root /var/www/html;
index index.php index.html;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.2-fpm.sock;
}
}
php -v
systemctl status php8.2-fpm
tail -f /var/log/php8.2-fpm.log
ls /run/php/
Nginx 里的 fastcgi_pass 必须匹配:
fastcgi_pass unix:/run/php/php8.2-fpm.sock;
echo "<?php phpinfo(); ?>" > /var/www/html/info.php
浏览器访问:
http://服务器IP/info.php
systemctl status mariadb
mysql -u root -p
tail -f /var/log/mysql/error.log
| 错误 | 原因 |
|---|---|
| Access denied | 用户权限 / 密码错 |
| 连接失败 | PHP 没装 mysql 扩展 |
php -m | grep mysql
如果没有:
apt install php-mysql
systemctl restart php8.2-fpm
chown -R www-data:www-data /var/www/html
chmod -R 755 /var/www/html
Debian 可忽略。
ss -lntp
ufw status
允许 HTTP:
ufw allow 80
ufw allow 443
✅ 按这个顺序查,效率最高:
nginx -tsystemctl status nginx php-fpm mariadb| 错误 | 解决 |
|---|---|
| 502 | PHP-FPM 没启动 |
| 空白页 | PHP 报错,看 log |
| 403 | 权限 / index |
| 数据库连接失败 | php-mysql 没装 |
如果你愿意,可以把 具体报错信息 / 日志 / 配置文件 贴出来,我可以帮你精准定位问题(比如 502、404、PHP 不解析等)。