去Apache官网下载httpd-2.4的源码。官网:https://httpd.apache.org/download.cgi#apache24

得到

httpd-2.4.41.tar.gz的源码包

进行解压缩

tar -xzvf httpd-2.4.41.tar.gz

 

安装C++编译器,首先连接到外网,利用在线软件包管理

执行

yum install gcc-c++

yum install gcc

 

进入到解压缩后的目录

执行./configure

提示apr不存在

于是去Apache官网下载apr:http://apr.apache.org/download.cgi

同样的解压缩然后./configure

make

sudo make install

安装完成

然后回到httpd目录继续执行./configure

又提示缺少Apr-util

于是通用的到了去Apache官网http://apr.apache.org/download.cgi下载到了 apr-util-1.6.1.tar.gz

同样的解压缩执行./configure

提示找不到apr(但是刚才我已经安装了)

错误提示如下解决了

centos源码安装httpd-2.4_其他

在执行make编译apr-util时发现

centos源码安装httpd-2.4_其他_02

通过sudoyum install expat-devel 安装好依赖

继续执行make

然后sudo make install

完成上面操作后,回到httpd目录继续执行./configure检查依赖

没有错误提示,继续执行make

出现如下错误

centos源码安装httpd-2.4_apache_03

百度得到解决方法,安装依赖

sudo yum install -y libxml2-devel

并且删除apr-util重新编译安装

执行完后继续进入httpd的目录

执行

make

sudo make install

没有报错安装成功

centos源码安装httpd-2.4_解压缩_04

最后启动httpd服务

sudo cp /usr/local/apache2/bin/apachectl /etc/init.d/

然后执行/etc/init.d/apachectl -k start

提示错误

centos源码安装httpd-2.4_其他_05

80端口被占用了不能绑定监听到80

于是修改http.conf文件修改端口以及ServerName localhost

sudo vim /usr/local/apache2/conf/httpd.conf

centos源码安装httpd-2.4_其他_06

然后执行/etc/init.d/apachectl -k start

又提示error_log这个文件权限问题

centos源码安装httpd-2.4_官网_07

于是干脆将整个目录的权限设定位777

然后继续上面的命令启动http

/etc/init.d/apachectl -k start

没有报错说明成功

测试输入主机ip:8888

虚拟机外访问不到,在centos的浏览器上能得到

It Works!

关闭虚拟机的防火墙

永久关闭:sudo systemctl disable firewalld.service

临时关闭:sudo systemctl stop firewalld.service

然后得到了显示结果

centos源码安装httpd-2.4_apache_08