在 Linux 下搭建或使用 LAMP(Linux + Apache + MySQL/MariaDB + PHP) 环境时,常见错误主要集中在服务未启动、权限问题、配置错误、版本不兼容等方面。下面按模块总结常见错误及排查思路。
现象
systemctl start httpd
Job for httpd.service failed
常见原因
排查
journalctl -xe
apachectl configtest
netstat -tunlp | grep :80
原因
解决
chmod 755 /var/www/html
chown -R apache:apache /var/www/html
setsebool -P httpd_can_network_connect 1
常见错误
检查
httpd -S
ERROR 1045 (28000): Access denied for user 'root'@'localhost'
原因
解决
systemctl stop mariadb
mysqld_safe --skip-grant-tables &
原因
journalctl -u mariadb
df -h
原因
GRANT ALL ON *.* TO 'user'@'%' IDENTIFIED BY 'pass';
firewall-cmd --add-port=3306/tcp --permanent
原因
检查
httpd -M | grep php
现象
Call to undefined function mysqli_connect()
解决
yum install php-mysqlnd
# 或
apt install php-mysql
原因
upload_max_filesize 过小upload_max_filesize = 20M
post_max_size = 20M
setenforce 0 # 临时关闭
永久:
vi /etc/selinux/config
SELINUX=disabled
firewall-cmd --list-all
firewall-cmd --add-service=http --permanent
firewall-cmd --add-service=https --permanent
systemctl status httpd mariadb
apachectl configtest
tail -f /var/log/httpd/error_log
tail -f /var/log/mariadb/mariadb.log
如果你愿意,可以告诉我:
我可以帮你精准定位问题。