导读 Apache 是世界使用排名第一的 Web 服务器软件。它可以运行在几乎所有广泛使用的计算机平台上,由于其跨平台和安全性被广泛使用,是最流行的 Web 服务器端软件之一。

下载安装包
[root@chao tools]# wget https://mirror.bit.edu.cn/apache/httpd/httpd-2.4.43.tar.gz
--2020-05-28 15:28:00--  https://mirror.bit.edu.cn/apache/httpd/httpd-2.4.43.tar.gz
正在解析主机 mirror.bit.edu.cn (mirror.bit.edu.cn)... 202.204.80.77, 219.143.204.117, 2001:da8:204:1205::22
正在连接 mirror.bit.edu.cn (mirror.bit.edu.cn)|202.204.80.77|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:9348230 (8.9M) [application/octet-stream]
正在保存至: “httpd-2.4.43.tar.gz”

100%[=========================================================================================================>] 9,348,230    204KB/s 用时 51s    

2020-05-28 15:28:57 (180 KB/s) - 已保存 “httpd-2.4.43.tar.gz” [9348230/9348230])
[root@chao tools]# ls
httpd-2.4.43.tar.gz
安装依赖组件
[root@chao yum.repos.d]# yum install apr apr-util apr-devel apr-util-devel pcre pcre-devel
已加载插件:fastestmirror, langpacks
123                                                                                                                         | 3.6 kB  00:00:00     
Loading mirror speeds from cached hostfile
正在解决依赖关系
--> 正在检查事务
---> 软件包 apr.x86_64.0.1.4.8-3.el7 将被 安装
---> 软件包 apr-devel.x86_64.0.1.4.8-3.el7 将被 安装
---> 软件包 apr-util.x86_64.0.1.5.2-6.el7 将被 安装
---> 软件包 apr-util-devel.x86_64.0.1.5.2-6.el7 将被 安装
--> 正在处理依赖关系 openldap-devel(x86-64),它被软件包 apr-util-devel-1.5.2-6.el7.x86_64 需要
--> 正在处理依赖关系 libdb-devel(x86-64),它被软件包 apr-util-devel-1.5.2-6.el7.x86_64 需要
--> 正在处理依赖关系 expat-devel(x86-64),它被软件包 apr-util-devel-1.5.2-6.el7.x86_64 需要
--> 正在检查事务
---> 软件包 expat-devel.x86_64.0.2.1.0-10.el7_3 将被 安装
---> 软件包 libdb-devel.x86_64.0.5.3.21-20.el7 将被 安装
---> 软件包 openldap-devel.x86_64.0.2.4.44-5.el7 将被 安装
--> 正在处理依赖关系 cyrus-sasl-devel(x86-64),它被软件包 openldap-devel-2.4.44-5.el7.x86_64 需要
--> 正在检查事务
---> 软件包 cyrus-sasl-devel.x86_64.0.2.1.26-21.el7 将被 安装
--> 解决依赖关系完成
......
安装编译环境
[root@chao httpd-2.4.43]# yum install -y gcc gcc-cc c++
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
没有可用软件包 gcc-cc。
没有可用软件包 c++。
正在解决依赖关系
--> 正在检查事务
---> 软件包 gcc.x86_64.0.4.8.5-16.el7 将被 安装
--> 正在处理依赖关系 cpp = 4.8.5-16.el7,它被软件包 gcc-4.8.5-16.el7.x86_64 需要
......
编译安装
[root@chao tools]# ls
httpd-2.4.43.tar.gz
[root@chao tools]# tar xf httpd-2.4.43.tar.gz 
[root@chao tools]# ls
httpd-2.4.43  httpd-2.4.43.tar.gz
[root@chao tools]# cd httpd-2.4.43/
[root@chao httpd-2.4.43]# ./configure --prefix=/usr/local/apache2 --enable-rewrite --enable-so
checking for chosen layout... Apache
checking for working mkdir -p... yes
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
configure: 
configure: Configuring Apache Portable Runtime library...
configure: 
checking for APR... yes
  setting CC to "gcc"
  setting CPP to "gcc -E"
  setting CFLAGS to "  -pthread"
  setting CPPFLAGS to " -DLINUX -D_REENTRANT -D_GNU_SOURCE"
  setting LDFLAGS to " "
......
config.status: creating include/ap_config_auto.h
config.status: executing default commands
configure: summary of build options:

    Server Version: 2.4.43
    Install prefix: /usr/local/apache2
    C compiler:     gcc -std=gnu99
    CFLAGS:           -pthread  
    CPPFLAGS:        -DLINUX -D_REENTRANT -D_GNU_SOURCE  
    LDFLAGS:           
    LIBS:             
    C preprocessor: gcc -E

执行make

[root@chao httpd-2.4.43]# make

执行make install

[root@chao httpd-2.4.43]# make install
开放防火墙端口
[root@chao ~]# firewall-cmd --zone=public --add-port=80/tcp --permanent 
success
[root@chao ~]# firewall-cmd --reload 
success
开启apache服务
[root@chao ~]# /usr/local/apache2/bin/apachectl start
测试

本文原创地址:https://www.linuxprobe.com/rhel-apache.html编辑:王华超,审核员:逄增宝