在 CentOS 里,“Apache2 报错”这种说法本身就容易踩坑,因为:
apache2所以如果你在 CentOS 上执行:
systemctl start apache2
会直接报错:
Failed to start apache2.service: Unit apache2.service not found.
✅ 正确做法:
systemctl start httpd
apachectl: command not found
或
httpd: command not found
原因:没装 httpd
yum install httpd -y
报错类似:
(98)Address already in use: AH00072: make_sock: could not bind to address
解决:
ss -lntp | grep ':80'
杀掉占用进程或修改监听端口。
访问网页 403 或启动失败:
setenforce 0 # 临时关闭
或永久:
sed -i 's/SELINUX=enforcing/SELINUX=permissive/' /etc/selinux/config
firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https
firewall-cmd --reload
httpd -t
如果报:
Syntax error on line XX
按提示修改 /etc/httpd/conf/httpd.conf
例如:
httpd: Syntax error: Module php7 module missing
CentOS 常见 PHP 用 php-fpm 或 mod_php
systemctl status httpd
journalctl -xe
httpd -t
ss -lntp
getenforce
你可以直接把 完整的报错信息贴出来(最好带命令和输出),我可以精准告诉你哪一行错了、怎么改。