Ubuntu 上 LNMP(Linux + Nginx + MySQL/MariaDB + PHP)启动失败 的原因很多,需要逐步排查。下面我按最常见原因 → 排查方法 → 解决思路给你一个系统性的指南。
LNMP 是组合服务,先分清是:
systemctl status nginx
systemctl status mysql
systemctl status php-fpm
(Ubuntu 20.04+ 通常是 php8.1-fpm 或 php-fpm)
sudo netstat -tunlp | grep ':80'
常见冲突:
apache2)解决:
sudo systemctl stop apache2
sudo systemctl disable apache2
sudo nginx -t
常见错误:
server_name 写错fastcgi_pass 路径不对root 目录不存在根据提示修改 /etc/nginx/
网站目录权限不对:
sudo chown -R www-data:www-data /var/www/
sudo chmod -R 755 /var/www/
sudo journalctl -xe
sudo cat /var/log/mysql/error.log
✅ 磁盘空间满了
df -h
✅ 权限错误
sudo chown -R mysql:mysql /var/lib/mysql
✅ 之前异常关机导致表损坏
sudo mysqlcheck --all-databases --auto-repair
✅ 配置文件错误
sudo mysqld --verbose --help
systemctl status php8.1-fpm
www.conf 中 listen 路径不存在fastcgi_pass 和 PHP-FPM 不匹配示例正确配置:
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.1-fpm.sock;
}
Ubuntu 默认用 ufw:
sudo ufw allow 'Nginx Full'
sudo ufw status
如果你用的是 lnmp.org 一键包:
lnmp status
lnmp restart
常见失败原因:
nginx -t
systemctl status nginx mysql php-fpm
df -h
journalctl -xe
你可以贴出:
journalctl 或 nginx -t 输出)我可以一步一步帮你精确修好。