在 CentOS 上启动 Apache(httpd),常见操作如下(适用于 CentOS 7/8/Stream,也兼容部分旧版本说明)。
sudo yum install httpd -y
CentOS 8 / Stream 可使用:
sudo dnf install httpd -y
sudo systemctl start httpd
sudo systemctl enable httpd
sudo systemctl status httpd
正常状态应显示:
Active: active (running)
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
sudo firewall-cmd --list-services
浏览器访问:
http://服务器IP
看到 Apache Test Page 即成功。
sudo systemctl stop httpd # 停止
sudo systemctl restart httpd # 重启
sudo systemctl reload httpd # 重新加载配置
| 项目 | 路径 |
|---|---|
| 主配置文件 | /etc/httpd/conf/httpd.conf |
| 虚拟主机 | /etc/httpd/conf.d/ |
| 网站根目录 | /var/www/html |
| 日志 | /var/log/httpd/ |
查看错误日志:
sudo journalctl -xe
sudo tail -n 50 /var/log/httpd/error_log
sudo netstat -tulnp | grep :80
如果你使用的是 CentOS 6 或需要 虚拟主机 / HTTPS / PHP 环境,可以告诉我,我可以给你更详细的配置示例。