1. 安装:`yum -y install httpd httpd-devel`2. 检查:`rpm -qa|grep httpd````text[root@localhost ~]# rpm -qa | grep httpdhttpd-devel-2.4.6-97.el7.centos.2.x86_64httpd-tools-2.4.6-97.el7.centos.2.x86_64httpd-2.4.6-97.el7.centos.2.x86_64
- 启动服务:
systemctl start httpd
[root@localhost ~]# systemctl start httpd[root@localhost ~]#[root@localhost ~]# systemctl status httpd● httpd.service - The Apache HTTP ServerLoaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)Active: active (running) since 三 2021-12-15 16:14:28 CST; 7s agoDocs: man:httpd(8)man:apachectl(8)Main PID: 8756 (httpd)Status: "Processing requests..."CGroup: /system.slice/httpd.service├─8756 /usr/sbin/httpd -DFOREGROUND├─8757 /usr/sbin/httpd -DFOREGROUND├─8758 /usr/sbin/httpd -DFOREGROUND├─8759 /usr/sbin/httpd -DFOREGROUND├─8760 /usr/sbin/httpd -DFOREGROUND└─8761 /usr/sbin/httpd -DFOREGROUND12月 15 16:14:28 localhost.localdomain systemd[1]: Starting The Apache HTTP Server...12月 15 16:14:28 localhost.localdomain httpd[8756]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, usin... message12月 15 16:14:28 localhost.localdomain systemd[1]: Started The Apache HTTP Server.Hint: Some lines were ellipsized, use -l to show in full.
- 解决80端口被占用,服务不能启动的问题- 方法1:找到占用80端口的进程(netstat -tnlp),使用kill命令结束进程- 方法2:修改Apache默认端口- 修改配置文件:`/etc/httpd/conf/httpd.conf`,将42行的`Listen 80`中80改为其他未被占用的端口即可,比如`Listen 8890`- 在安全策略中配置新端口(CentOS中的SELinux不允许访问不在安全策略中的端口)- 查询semanage:
[root@localhost var]# yum provides semanage已加载插件:fastestmirrorLoading mirror speeds from cached hostfile* base: mirror.lzu.edu.cn* extras: mirror.lzu.edu.cn* updates: mirror.lzu.edu.cnpolicycoreutils-python-2.5-34.el7.x86_64 : SELinux policy core python utilities
- 安装semanage命令:`yum -y install policycoreutils-python-2.5-34.e17.x86_64`- 查询SELinux安全策略支持的端口:`semanage port -l | grep http`
[root@localhost ~]# semanage port -l | grep httphttp_cache_port_t tcp 8080, 8118, 8123, 10001-10010http_cache_port_t udp 3130http_port_t tcp 80, 81, 443, 488, 8008, 8009, 8443, 9000pegasus_http_port_t tcp 5988pegasus_https_port_t tcp 5989
- 将Apache配置文件中设置新端口添加到安全策略中:`semanage port -a -t``http_port_t -p tcp 8890`
[root@localhost ~]# semanage port -l | grep httphttp_cache_port_t tcp 8080, 8118, 8123, 10001-10010http_cache_port_t udp 3130http_port_t tcp 8001, 80, 81, 443, 488, 8008, 8009, 8443, 9000pegasus_http_port_t tcp 5988pegasus_https_port_t tcp 5989
- 启动httpd服务,打开浏览器访问`http://虚拟机ip:新端口`
- 关闭防火墙:
systemctl stop firewalld
[root@localhost ~]# systemctl stop firewalld[root@localhost ~]# systemctl status firewalld● firewalld.service - firewalld - dynamic firewall daemonLoaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)Active: inactive (dead) since 三 2021-12-15 16:14:16 CST; 1min 4s agoDocs: man:firewalld(1)Process: 725 ExecStart=/usr/sbin/firewalld --nofork --nopid $FIREWALLD_ARGS (code=exited, status=0/SUCCESS)Main PID: 725 (code=exited, status=0/SUCCESS)10月 25 18:22:00 localhost.localdomain systemd[1]: Starting firewalld - dynamic firewall daemon...10月 25 18:22:01 localhost.localdomain systemd[1]: Started firewalld - dynamic firewall daemon.10月 25 18:22:01 localhost.localdomain firewalld[725]: WARNING: AllowZoneDrifting is enabled. This is considered an insecure configuration optio...it now.12月 15 16:14:15 localhost.localdomain systemd[1]: Stopping firewalld - dynamic firewall daemon...12月 15 16:14:16 localhost.localdomain systemd[1]: Stopped firewalld - dynamic firewall daemon.Hint: Some lines were ellipsized, use -l to show in full.
- 在主机浏览器中输入地址:
http://虚拟机ip访问Apache的测试页面
```

