Apache是一个基金会的名字,httpd才是我们要安装的软件包,早期它的名字就叫apache Apache官网www.apache.org

1、下载安装包(若报404可自行查看更新版本):

wget http://mirrors.cnnic.cn/apache/httpd/httpd-2.4.37.tar.gz
wget http://mirrors.hust.edu.cn/apache/apr/apr-1.6.5.tar.gz
wget http://mirrors.hust.edu.cn/apache/apr/apr-util-1.6.1.tar.gz

apr和apr-util是一个通用的函数库,它让httpd可以不关心底层的操作系统平台,可以很方便地移植(从linux移植到windows)

2、解压:

tar -zxvf httpd-2.4.37.tar.gz
tar -zxvf apr-1.6.5.tar.gz
tar -zxvf apr-util-1.6.1.tar.gz

3、首先安装apr

cd /usr/local/src/apr-1.6.5
./configure --prefix=/usr/local/apr

若安装时提示下图错误信息解决办法: 执行./configure命令时,在遇到以上错误是,这个是因为gcc包没有安装。对于这个问题,使用yum install -y gcc就可以了。

make && make install

4、安装apr-util

cd /usr/local/src/apr-util-1.6.1
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
make && make install

编译时若出现如下图错误解决办法: 问题:缺少 expat库 解决方法 : yum install -y expat-devel 再次编译即可

5、安装httpd cd /usr/local/src/httpd-2.4.37 .``` /configure
--prefix=/usr/local/apache2.4
--with-apr=/usr/local/apr
--with-apr-util=/usr/local/apr-util
--enable-so
--enable-mods-shared=most

//这里的反斜杠是脱义字符,加上它我们可以把一行命令写成多行
或者
./configure --prefix=/usr/local/apache2.4 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-so --enable-mods-shared=mos

若出现如下图错误解决办法:
![](https://s1.51cto.com/images/blog/201901/22/1ecb8ecd629ea315dba0a9d4ad517d7f.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_30,g_se,x_10,y_10,shadow_20,type_ZmFuZ3poZW5naGVpdGk=)
解决方法:yum install -y pcre-devel
后再执行./configure

之后若出现如下错误:

/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_ErrorString' /usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_SetElementHandler' collect2: error: ld returned 1 exit status
解决办法:
在configure后加上 “--with-included-apr”。再重新编译, make, make install. 即可。
问题又来了,加上--with-included-apr之后,编译,报错如下:
configure: error: Bundled APR requested but not found at ./srclib/. Download and unpack the corresponding apr and apr-util packages to ./srclib/.
错误为:apr,apr-util缺失,需要下载并解压到./srclib/目录下
解决办法:
cd /usr/local/src/

cp -r apr-1.5.2 /usr/local/src/httpd-2.4.7/srclib/apr
cp -r apr-util-1.5.4 /usr/local/src/httpd-2.4.7/srclib/apr-util
再次执行./configure就不会报错,make,make install也不会报错
或者使用1.5版本的apr及apr-util

make && make install

扩展:
ls /usr/local/apache2.4/modules     //modules存放扩展模块
/usr/local/apache2.4/bin/httpd -M //查看加载的模块
或者/usr/local/apache2.4/bin/apachectl -M



6、启动
/usr/local/apache2.4/bin/apachectl start

查看端口:netstat -lntp