在 CentOS + LAMP(Linux + Apache + MySQL + PHP) 环境下出现 HTTP 500 内部服务器错误,通常不是单一原因,而是服务端脚本或配置出错。下面按最常见原因 → 排查方法给你一个系统清单。
浏览器访问后:
500 Internal Server Error<?php
echo "test"
// 少了分号
✅ 排查:
php -l /var/www/html/index.php
.htaccess 配置错误常见于:
✅ 排查:
mv .htaccess .htaccess.bak
如果 500 消失 → 就是它的问题
Apache 用户通常是:
apacheapache 或 www-data❌ 错误示例:
chmod 777 -R /var/www/html # 不安全
✅ 推荐:
chown -R apache:apache /var/www/html
chmod 755 /var/www/html
如:mysqli、gd、mbstring
✅ 检查:
php -m | grep mysqli
CentOS 安装示例:
yum install php-mysqli
systemctl restart httpd
✅ 查看是否被拒:
getenforce
tail /var/log/audit/audit.log | grep httpd
✅ 临时测试:
setenforce 0
✅ 正确做法(不关 SELinux):
chcon -R -t httpd_sys_content_t /var/www/html
tail -f /var/log/httpd/error_log
常见日志示例:
PHP Parse errorPermission deniedInvalid command 'RewriteEngine'在 php.ini:
display_errors = On
error_reporting = E_ALL
重启 Apache:
systemctl restart httpd
error_log.htaccessphp -l 检查 PHP你可以直接贴:
error_log 报错内容我可以精确告诉你哪一行配置或代码有问题。