计算机知识分享网

【apache】centos快速部署Apache服务器

1.在线安装
sudo yum install httpd -y
2.启动httpd服务,并设置开机自启
sudo systemctl start httpd
sudo systemctl enable httpd
3. 检查服务状态
sudo systemctl status httpd
4.开放端口
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
5.测试安装
curl http://localhost
6.常用管理命令
sudo systemctl restart httpd
sudo systemctl stop httpd

# 重新加载配置(不中断现有连接)
sudo systemctl reload httpd
# 在CentOS/RHEL系统中,默认的SELinux可能会阻止Apache访问某些文件,如果遇到权限问题,可以临时禁用SELinux测试:
sudo setenforce 0
7.查看日志
# 访问日志
tail -f /var/log/httpd/access_log

# 查看错误日志
tail -f /var/log/httpd/error_log
8.配置文件位置说明
/etc/httpd/conf/httpd.conf - 主配置文件
/etc/httpd/conf.d/ - 额外配置文件目录
/var/www/html/ - 默认网站根目录,如果权限不足,可以给755权限

#Apache