“Linux LAMP 报错”这个问题范围比较广,LAMP = Linux + Apache + MySQL/MariaDB + PHP,不同组件报错原因完全不同。
我先把最常见 LAMP 报错及排查思路整理给你,你对照看看是哪一种;如果方便,把具体报错信息贴出来,我可以直接帮你定位。
journalctl -xe
tail -f /var/log/apache2/error.log # Ubuntu/Debian
tail -f /var/log/httpd/error_log # CentOS/RHEL
tail -f /var/log/mysql/error.log
systemctl status apache2
systemctl status mysql
Address already in use: AH00072: make_sock: could not bind to address
✅ 解决:
netstat -tunlp | grep 80
杀掉占用进程或改端口。
You don't have permission to access this resource
✅ 常见原因:
解决:
chmod -R 755 /var/www/html
chown -R www-data:www-data /var/www/html
CentOS:
setenforce 0
✅ 没装 PHP 模块:
apt install libapache2-mod-php
systemctl restart apache2
Can't connect to local MySQL server
✅ 查看:
systemctl status mysql
journalctl -xe
常见原因:
chown -R mysql:mysql /var/lib/mysql
Access denied for user 'root'@'localhost'
✅ 重置密码:
mysqld_safe --skip-grant-tables &
✅ 打开错误显示:
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
Class 'mysqli' not found
✅ 安装:
apt install php-mysql
systemctl restart apache2
请把以下信息发我:
我可以直接给你一步一步可执行的解决方案。