Debian LNMP常见错误与排查修复指南
一、快速排查流程
systemctl status nginx、systemctl status mysql、systemctl status php*-fpmnginx -ttail -f /var/log/syslog、journalctl -xe/var/log/nginx/error.log;MySQL /var/log/mysql/error.log;PHP-FPM /var/log/php*-fpm.logtop、free -h、df -hping、curl -I http://127.0.0.1cp file file.bak-$(date +%F)systemctl reload nginx、systemctl restart php*-fpm、systemctl restart mysql二、高频错误与修复
apt update 失败、导入 GPG 时报错或域名无法解析deb https://mirrors.aliyun.com/debian/ stretch main
deb https://mirrors.aliyun.com/debian/ stretch-updates main
deb https://mirrors.aliyun.com/debian-security/ stretch/updates main
执行:apt updateping 域名,能通再 wget 下载 .gpg 并 apt-key add,必要时重试几次cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak-$(date +%F),再按需合并关键段落systemctl status php*-fpm 显示 failedmkdir -p /var/run/php/ && chown www-data:www-data /var/run/php/systemctl restart php*-fpmpm.max_children;脚本执行时间长时提高 max_execution_timelisten.backlog(如 1024)pm.max_requests = 200(缓解内存泄漏导致的退化)perl: warning: Setting locale failed.en_US.UTF-8 或 zh_CN.UTF-8),执行 dpkg-reconfigure locales 后重新登录或 source /etc/default/locale三、配置与优化要点
fastcgi_pass 127.0.0.1:9000;,则 PHP-FPM 的 listen 应为 127.0.0.1:9000;若使用 unix socket(如 /run/php/phpX.Y-fpm.sock),需确保 Nginx worker 用户对该 socket 有读/写权限,常见属主为 www-data:www-datapm.max_children、pm.start_servers、pm.min_spare_servers、pm.max_spare_serverspm.max_requests = 200 可周期性重启子进程,缓解潜在内存泄漏max_execution_time、max_input_timefastcgi_read_timeout、fastcgi_send_timeout、proxy_read_timeout(如 Nginx 作为反向代理时)net.core.somaxconn 与之匹配apt update && apt upgrade,变更前备份配置与数据目录(如 /var/www、/etc/mysql、/etc/nginx)四、一键安装与分步安装的选择
systemctl status 与 nginx -t 校验,便于快速定位问题来源