要准确回答 CentOS 上 Apache 为什么报错,需要看具体的报错信息。不过我可以先给你列出 CentOS + Apache 最常见的报错原因和排查方法,你可以对照看看。
sudo systemctl status httpd
sudo journalctl -xe
sudo tail -n 50 /var/log/httpd/error_log
把里面的 红色报错内容 发出来,我可以精准判断。
systemctl start httpd
报错示例:
Job for httpd.service failed
常见原因:
检查:
httpd -t
ss -lntp | grep ':80'
如果是 nginx:
systemctl stop nginx
报错常含:
Permission denied
临时关闭测试:
setenforce 0
如果好了,说明是 SELinux 问题。
永久解决(允许 httpd):
setsebool -P httpd_can_network_connect 1
firewall-cmd --list-all
放行:
firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https
firewall-cmd --reload
例如:
</VirtualHost>检查:
httpd -t
输出:
Syntax OK
Apache 用户是:
apache
网站目录需有读权限:
chown -R apache:apache /var/www/html
chmod -R 755 /var/www/html
php 或 mod_phpyum install php
systemctl restart httpd
请把下面任意一种发我:
httpd -t 输出/var/log/httpd/error_log 最后 20 行我可以直接告诉你 是哪一行配置或系统问题导致的。