CentOS7源码包安装apache

本文详细介绍了在Linux环境下从源码安装Apache的过程,包括解决依赖问题、安装APR、APR-util和PCRE等必要组件的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、下载apache源码包
1.下载地址:http://httpd.apache.org/download.cgi,下载 httpd-2.4.20.tar.gz
2.上传到服务器目录,/tmp/
解压:tar -zxvf httpd-2.4.20.tar.gz
进入目录:cd httpd-2.4.20
3.编译刚刚解压的源文件,
配置编译参数:
./configure –prefix=/usr/local/apache24/ (配置安装目录 /usr/local/apache24/)
4.正常执行 (说明你的linux安装过apache,或者已经安装了所需的依赖包。)
make
make install
错误信息:
*checking for APR… no
configure: error: APR not found. Please read the documentation.*
解决方案:
二、安装apr
Apache在安装时需要一些准备环境,这里需要安装另外一个东西 APR(Apache Portable Runtime)。

下载地址: http://archive.apache.org/dist/apr/ 同样找最新版本
得到文件:apr-1.5.2.tar.gz
解压:tar -zxvf apr-1.5.2.tar.gz
cd /usr/local/installers/apr-1.5.2    
 ./configure --prefix=/usr/local/apr/   
make 
make install 


完成后在指定地址生成目录和文件

三、尝试安装apache
接着装apache,切换到源代码目录设置编译参数: ./configure –prefix=/usr/local/apache24/

还是报上面的错,
        *checking for APR... no
        configure: error: APR not found.  Please read the documentation.*
        解决方案:
这是因为上面自定义了apr的安装目录,所以得把这个信息告诉apache。
./configure --prefix=/usr/local/apache24/  --with-apr=/usr/local/apr/  

错误信息:
*checking for APR-util… no
configure: error: APR-util not found. Please read the documentation.*

解决方案: 下载 APR-util
下载地址:http://archive.apache.org/dist/apr/ 找最新版本

得到文件:apr-util-1.5.4.tar.gz

解压: tar -zxvf apr-util-1.5.4.tar.gz

编译:
    cd /usr/local/installers/apr-util-1.5.4  

     ./configure --prefix=/usr/local/apr-util/   
这次运行会报错:
    checking for APR... no
    configure: error: APR could not be located. Please use the --with-apr option.
看到提示你就懂了,--with-apr:
    ./configure --prefix=/usr/local/apr-util/ --with-apr=/usr/local/apr/  

     make  

     make install   
    在你指定的安装地址生成目录就说明安装成功了

四. 继续安装apache
切到apache源代码目录下运行:
./configure –prefix=/usr/local/apache/ –with-apr=/usr/local/apr/ –with-apr-util=/usr/local/apr-util/
照旧报错:
*checking for pcre-config… false
configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/*
解决方案:发现还是少环境,下载 PCRE
下载地址: http://jaist.dl.sourceforge.net/project/pcre/pcre/ 找最新版下

得到文件: pcre-8.37.tar.gz

解压:tar -zxvf pcre-8.37.tar.gz

编译:
    cd /usr/local/hunter/installers/pcre-8.37  

    ./configure --prefix=/usr/local/pcre/  
这次错误信息如下:
    *checking for windows.h... no
    configure: error: You need a C++ compiler for C++ support.*
解决方案:
    yum -y install gcc-c++

五. 继续apache的安装,一定要在参数中带上以上3种环境配置:
./configure –prefix=/usr/local/apache/ –with-apr=/usr/local/apr/ –with-apr-util=/usr/local/apr-util/ –with-pcre=/usr/local/pcre/

make

make install

最后测试apache
/usr/local/apache24/bin/apachectl start (启动apache)

/usr/local/apache24/bin/apachectl stop          (停止apache)
                    <link rel="stylesheet" href="https://csdnimg.cn/release/phoenix/production/markdown_views-68a8aad09e.css">
                        </div>

Apache加入到系统服务里面:
  cp /安装目录下/apache/bin/apachectl /etc/rc.d/init.d/httpd
  修改httpd
  在文件头部加入如下内容:
  ###
  # Comments to support chkconfig on RedHat Linux
  # chkconfig: 2345 90 90
  # description:http server
  ###
  保存
  在打入
  #chkconfig –add httpd
  #chkconfig –level 345 httpd on

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值