排查 Linux 下 LAMP(Linux + Apache + MySQL/MariaDB + PHP) 故障,通常按“分层定位、看日志、逐项验证”的思路进行。下面给你一套实用排查流程,从最常见的问题开始。
先确认是哪一类问题:
systemctl status httpd # 或 apache2
systemctl status mariadb # 或 mysqld
systemctl status php-fpm # 如果用了 php-fpm
常见命令:
ps aux | grep httpd
ps aux | grep mysql
netstat -tunlp | grep :80
netstat -tunlp | grep :3306
✅ 服务没起 → 先启动:
systemctl start httpd
systemctl start mariadb
tail -f /var/log/httpd/error_log
# 或
tail -f /var/log/apache2/error.log
常见错误:
Permission denied → 文件/目录权限问题DocumentRoot does not exist → 配置路径错403 Forbidden → 目录权限或 SELinuxapachectl -t # 语法检查
若报错,先修配置。
ls -l /var/www/html
getenforce
如果是 Enforcing 且网站异常:
setenforce 0 # 临时关闭测试
建测试文件:
<?php phpinfo(); ?>
访问:
http://ip/info.php
tail -f /var/log/php-fpm/error.log
# 或
vi /etc/php.ini # 看 error_log
php-mysqldisplay_errors = Offshort_open_tag 问题apache 用户mysql -u root -p
连不上常见原因:
tail -f /var/log/mariadb/mariadb.log
# 或
tail -f /var/log/mysql/error.log
firewall-cmd --list-all
iptables -L -n
.htaccessconfig.php)重点看:
MaxClients 满df -h
free -m
✅ 服务起没起
✅ 端口通不通
✅ 错误日志说什么
✅ PHP 是否解析
✅ 数据库能否连
✅ 权限 & SELinux
✅ 防火墙
如果你愿意,可以把具体报错信息或现象发出来(比如 500 错误、白屏、连不上数据库),我可以直接帮你定位到具体原因。