在 CentOS 上 LNMP(Linux + Nginx + MySQL/MariaDB + PHP)启动失败,原因通常是多方面的。下面按最常见原因 → 排查方法 → 解决思路给你一个系统性的排查清单。
LNMP 中任意一层失败,都会表现为“启动失败”。
systemctl status nginx
systemctl status mysqld # 或 mariadb
systemctl status php-fpm
看哪一个 failed,再针对性处理。
ss -lntp | grep ':80'
如果有 httpd 或其他进程:
systemctl stop httpd
systemctl disable httpd
nginx -t
常见错误:
server_name 写错fastcgi_pass 路径不对; 或 }修复后:
systemctl restart nginx
查看:
getenforce
如果是 Enforcing:
setenforce 0 # 临时
永久关闭(不推荐生产):
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
或允许 Nginx:
setsebool -P httpd_can_network_connect 1
ls -ld /var/lib/mysql
正确权限:
chown -R mysql:mysql /var/lib/mysql
ss -lntp | grep 3306
cat /var/log/mysqld.log
# 或
journalctl -xe
常见错误:
php -v
rpm -qa | grep php
CentOS 常见:
vim /etc/php-fpm.d/www.conf
确认:
listen = /run/php-fpm/www.sock
Nginx 中必须一致。
systemctl status php-fpm
journalctl -xe
firewall-cmd --list-all
允许:
firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https
firewall-cmd --reload
systemctl restart nginx mysqld php-fpm
systemctl status nginx mysqld php-fpm
你可以直接贴出:
cat /etc/redhat-release)我可以直接帮你定位到“哪一行错了”。