“Linux LNMP 报错”这个范围很大,不能一句话给出解决办法。你可以按下面思路快速定位 + 常见错误处理,大多数问题都能解决。
LNMP = Linux + Nginx + MySQL/MariaDB + PHP
报错通常出现在:
# Nginx 错误日志
tail -f /var/log/nginx/error.log
# PHP 错误日志(路径可能不同)
tail -f /var/log/php-fpm.log
# 或
tail -f /var/log/php7.x-fpm.log
# MySQL 日志
tail -f /var/log/mysqld.log
# 或
journalctl -u mariadb
nginx -t
常见原因:
解决:
systemctl stop httpd
systemctl restart nginx
原因一般是 PHP-FPM 没运行或 socket 配置错
检查:
ps aux | grep php-fpm
Nginx 配置中:
fastcgi_pass unix:/run/php-fpm/www.sock;
必须和 php-fpm 配置一致。
解决:
systemctl restart php-fpm
开启错误显示:
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
常见原因:
systemctl status mysqld
常见原因:
解决示例:
chown -R mysql:mysql /var/lib/mysql
systemctl restart mysqld
网站目录建议:
chown -R www-data:www-data /var/www/html
chmod -R 755 /var/www/html
(CentOS 可能是 nginx:nginx)
# 开放 80/443
firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https
firewall-cmd --reload
请把以下信息发我:
例如:
CentOS 7,LNMP 一键包,访问网站 502,nginx 日志显示 connect() to unix:/run/php-fpm/www.sock failed
我可以直接给你精确命令。