在 CentOS 上调试 LAMP(Linux + Apache + MySQL/MariaDB + PHP),通常按“分层排查”的思路进行。下面按常见问题 → 调试方法 → 命令来说明。
systemctl status httpd
启动 / 重启 / 开机自启:
systemctl start httpd
systemctl restart httpd
systemctl enable httpd
systemctl status mariadb
# 或
systemctl status mysqld
php -v
httpd -M | grep php
tail -f /var/log/httpd/error_log
访问页面时实时观察:
tail -f /var/log/httpd/access_log
httpd -t
输出 Syntax OK 表示配置没问题。
编辑 php.ini:
vi /etc/php.ini
修改:
display_errors = On
error_reporting = E_ALL
重启 Apache:
systemctl restart httpd
vi /var/www/html/info.php
内容:
<?php
phpinfo();
浏览器访问:
http://服务器IP/info.php
tail -f /var/log/php-fpm/error.log
# 或
tail -f /var/log/httpd/error_log
mysql -u root -p
tail -f /var/log/mariadb/mariadb.log
<?php
$conn = new mysqli("localhost","user","pass","db");
if ($conn->connect_error) {
die("连接失败: " . $conn->connect_error);
}
echo "数据库连接成功";
查看:
getenforce
临时关闭(不推荐生产):
setenforce 0
正确做法:
chcon -R -t httpd_sys_content_t /var/www/html
firewall-cmd --list-all
firewall-cmd --add-service=http --permanent
firewall-cmd --add-service=https --permanent
firewall-cmd --reload
systemctl status httpdtail error_logdisplay_errorsmysql -u 测试ls -l /var/www如果你能告诉我:
我可以直接帮你定位问题。