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

    ``` image.png