Linux学习之安装Apache httpd中,APR not found,APR-util not found,pcre-config for libpcre not found问题解决

小背景

这几天折腾Linux,跟着别人一步一步进行Linux中httpd服务的安装,踩了很多坑,幸运的是最后还是完成了,下面是对过程的简单记录。

实验环境

  • Linux环境:CentOS Linux 7
  • Windows环境:win10
  • 虚拟机:VMware® Workstation 12 Pro

实验过程

  1. 在本次实验中,我们使用的是源码包安装的方式和yum在线安装两种安装形式,最后会有个小的对比。
  2. 首先下载apache的安装包,点此下载,解压:tar -zvxf httpd-2.4.39.tar.gz;进入解压目录:cd httpd-2.4.39;如下图所示,在INSTALL文件中其实提供了安装的具体步骤,就是通过三条命令搞定。./configure --prefix=/usr/local/apache2 ; make; make install ; 即可,之后启动服务。这个prefix就是你软件安装的位置,通过源码安装软件的时候一般情况下都安装在/usr/local 的目录下,因此此次实验也是在这个目录下面。
    Linux学习之安装Apache httpd中,APR not found,APR-util not found,pcre-config for libpcre not found问题解决Linux学习之安装Apache httpd中,APR not found,APR-util not found,pcre-config for libpcre not found问题解决
  3. 原来以为我也会这么简单就安装好了,但是当我运行第一个命令的时候就报错:APR not found,那么只好去下载APR的库,点此下载,下载之后和上述操作一样,解压–> 进入目录–>make && make install,安装好了之后,再次进入httpd的目录中,再次configure一次,这次的命令需要加上新的后缀:./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr,其中后面的是你安装的APR所在的目录。
  4. 这次APR not found错误解决了,出现了新的错误:APR-util not found,然后就去下载APR-util的库呗,点此下载,下载好了之后,再来一遍:解压–> 进入目录–>make && make install,安装好了之后,再次进入httpd的目录中,再次configure一次,这次的命令需要加上新的后缀:./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util,其中后面的是你安装的APR-util所在的目录。
  5. 好了这次configure执行成功了,但是在make的时候又出现了错误:pcre-config for libpcre not found,这个那还和前面一样呗,先去下载再说,下载目录为:点此下载
  6. Linux学习之安装Apache httpd中,APR not found,APR-util not found,pcre-config for libpcre not found问题解决如上图所示,由于一开始我下载的是pcre2,安装好了之后,在httpd服务make编译的时候还是出现了错误,Did not find pcre-config script,后来参考了这篇论坛问答里的老哥说的,不要安装pcre2,直接安装pcre即可,于是又进入/usr/local目录下面把pcre2的目录删掉,其实就是卸载pcre2软件,之后重新安装了pcre,之后再次进入,httpd目录下面,执行命令:./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre,这次前面的错误没有了,但是出现了一个和之前apr相关的错误:can not find libapr-0.la in /usr/local/apr-1.6.1/lib,出现这个错误的原因是:APR-util是依赖于APR的库的而在配置文件中的安装目录可能和自己的安装目录不一致,因此直接进入APR的库目录,将配置文件修改,如下图所示:
  7. cd /usr/local/apr-util/lib
    Linux学习之安装Apache httpd中,APR not found,APR-util not found,pcre-config for libpcre not found问题解决
  8. vi libaprutil-1.la ,找到配置依赖位置,并进行修改(此处需要根据自身的安装位置进行调整)
    Linux学习之安装Apache httpd中,APR not found,APR-util not found,pcre-config for libpcre not found问题解决
  9. 之后最后一次运行下面两个命令,httpd终于安装成功了:
  • ./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre
  • make && make install
  1. 安装成功之后,就需要启动服务,源码安装的一般直接在安装目录启动即可,通过/usr/local/apache2/bin/apachectl start命令启动服务,此时会提示缺少服务器名称,这是小问题没啥关系。但是我想使用本地电脑的浏览器访问虚拟机的页面,一直无法连接。
  2. 针对上面的问题,首先想到将虚拟机和本机的网络连接方式换成桥接的方式,如下图所示。
    Linux学习之安装Apache httpd中,APR not found,APR-util not found,pcre-config for libpcre not found问题解决
  3. 换好之后,通过 ifconfig获取到虚拟机的IP地址
    Linux学习之安装Apache httpd中,APR not found,APR-util not found,pcre-config for libpcre not found问题解决
  4. 之后在本地通过ping命令发现可以通,但是在浏览器中输入IP地址还是无法连接,参考这篇文章首先查看防火墙的状态(systemctl status firewalld.service),之后将防火墙关闭(systemctl stop firewalld.service ),再次查看防火墙状态发现已经关闭了。
    Linux学习之安装Apache httpd中,APR not found,APR-util not found,pcre-config for libpcre not found问题解决
  5. 最后在本机浏览器中输入IP地址,终于好了!
    Linux学习之安装Apache httpd中,APR not found,APR-util not found,pcre-config for libpcre not found问题解决
  6. 前面有提到会使用两种方法来安装httpd服务,因此我们首先将源码安装的httpd服务关闭,/usr/local/apache2/bin/apachectl stop,关闭之后通过yum install -y httpd安装httpd服务,yum在线安装之后一般启动命令会在/sbin/目录下,可以直接在任意目录下使用,启动yum安装的http服务apachectl start,在本机的浏览器中刷新一下会发现两者的页面是不一样的,如下所示:Linux学习之安装Apache httpd中,APR not found,APR-util not found,pcre-config for libpcre not found问题解决
  7. 至此CenOS Linux 7下安装httpd服务实验就算结束了,在此过程中踩了很多坑,但也学到了很多,也希望可以帮助到其他一起来踩坑的小伙伴,写的不好还请轻喷。