Linux学习——源码安装步骤 “以httpd为例”

这篇博客详细介绍了在Linux系统中如何进行httpd的源码安装,包括安装编译工具、解压httpd源码、配置安装路径,以及安装依赖的APR、APR-util和pcre库。在安装过程中遇到的错误和解决办法也进行了说明。

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

一、开胃小菜

1、安装相应编译工具: gcc  gcc-c++  gcc-c77  ; expat-devel  -y
2、分析安装平台
3、下载源码包:
  官方站点  例:[http://mirror.bit.edu.cn/apache/apr/](http://mirror.bit.edu.cn/apache/apr/)
 保存位置:usr/local/src

让我们先开始必要的准备工具

安装编译工具

首先,我们先来安装wget命令

[root@localhost ~]# mount /dev/sr0 /media/
mount: /dev/sr0 is write-protected, mounting read-only
[root@localhost ~]# yum install wget
...
Installed:
wget.x86_64 0:1.14-18.el7
Complete!

中间无数个省略号。。哈哈,看到了Complete!就知道已经安装完成了

接下来正式开始安装编译工具

[root@localhost ~]# yum install gcc gcc-c++ gcc-c77
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
...
Complete!

二、编译安装程序源码包步骤

1、./configure  软件配置和系统检查
  a.指定安装路径 --prefix=/usr/local/apache
  b.启用禁用功能  --enable-ssl
  c.与其他软件关联 --with-apr
  d.检查
  定义好的功能和检测的安装环境信息写入到 makefile文件中,
2、 make
3、 make install
【注】:如果make出错 需要执行 make clean    并且最好重新 ./configure
4、PREFIX/bin/*ctl   start  
5、cp  PREFIX/bin/*ctl  /etc/rc.d/init.d/httpd 
  service  httpd  start

三、开始安装httpd

使用官方站点的链接安装【如下】,或者在电脑上下载之后直接拖入到ssh工具里我们指定的路径下

[root@localhost ~]# cd /usr/local/src
[root@localhost src]# wget http://mirror.bit.edu.cn/apache/httpd/httpd-2.4.41.tar.gz
--2020-03-19 19:26:57--  http://mirror.bit.edu.cn/apache/httpd/httpd-2.4.41.tar.gz
Resolving mirror.bit.edu.cn (mirror.bit.edu.cn)... 202.204.80.77, 219.143.204.117, 2001:da8:204:1205::22
Connecting to mirror.bit.edu.cn (mirror.bit.edu.cn)|202.204.80.77|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 9267917 (8.8M) [application/octet-stream]
Saving to: ‘httpd-2.4.41.tar.gz’
100%[================================================>] 9,267,917    303KB/s   in 30s
2020-03-19 19:27:27 (305 KB/s) - ‘httpd-2.4.41.tar.gz’ saved [9267917/9267917]
解压
[root@localhost src]# tar -xvzf httpd-2.4.41.tar.gz
httpd-2.4.41/
...
httpd-2.4.41/srclib/
httpd-2.4.41/srclib/Makefile.in
[root@localhost src]# ls
httpd-2.4.41  httpd-2.4.41.tar.gz
软件配置和系统检查,并指定安装路径
[root@localhost src]# cd httpd-2.4.41
[root@localhost httpd-2.4.41]# ./configure --prefix=/usr/local/httpd
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... no
configure: error: APR not found.  Please read the documentation.

四、关联软件的安装

APR安装

如上所示,系统报错:APR not found,所以现在我们就来安装APR

首先,我们将在官方站点下载的压缩包移入usr/local/src中
在这里插入图片描述

  • 安装解压apr
[root@localhost httpd-2.4.41]# cd ..
[root@localhost src]# ls
apr-1.6.5.tar.gz       httpd-2.4.41         pcre-8.42.tar.gz
apr-util-1.6.1.tar.gz  httpd-2.4.41.tar.gz
[root@localhost src]# tar -zxvf apr-1.6.5.tar.gz

在这里插入图片描述
这个就是我们解压之后的文件

  • 软件配置和系统检查,并指定安装路径
[root@localhost src]# cd apr-1.6.5
[root@localhost apr-1.6.5]# ./configure --prefix=/usr/local/apr
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
Configuring APR library
Platform: x86_64-pc-linux-gnu
...
[root@localhost apr-1.6.5]# make
...
[root@localhost apr-1.6.5]# make install
...
[root@localhost httpd-2.4.41]# ./configure --prefix=/usr/local/apache --with-apr=/usr/local/apr
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 " -g -O2 -pthread"
  setting CPPFLAGS to " -DLINUX -D_REENTRANT -D_GNU_SOURCE"
  setting LDFLAGS to " "
configure:
configure: Configuring Apache Portable Runtime Utility library...
configure:
checking for APR-util... no
configure: error: APR-util not found.  
APR-util安装

看到上面代码行的报错了吗?APR-util not found

so,我们来到了关联软件的第二个,给自己加油打打气吧!我们都很厉害哪

其实安装方式同APR一样,让我们再来回顾一遍吧

  • 安装解压APR-util
[root@localhost src]# tar -xzvf apr-util-1.6.1.tar.gz

在这里插入图片描述
同样的,解压后便出现了APR-util 的解压文件

  • 软件配置和系统检查,并指定安装路径
[root@localhost src]# cd apr-util-1.6.1
[root@localhost apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util
...
checking for APR... no
configure: error: APR could not be located. Please use the --with-apr option.

这里出现了错误,为什么呢?因为我们没有关联apr,这里提醒了我们,哦,看来所有的关联软件都是需要我们关联在一起的
再来一次吧

[root@localhost apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr

没有报错,我们接着来

[root@localhost apr-util-1.6.1]# make
...
xml/apr_xml.c:35:19: fatal error: expat.h: No such file or directory
 #include <expat.h>
                   ^
compilation terminated.
make[1]: *** [xml/apr_xml.lo] Error 1
make[1]: Leaving directory `/usr/local/src/apr-util-1.6.1'
make: *** [all-recursive] Error 1

哦,怎么又报错了?别急,我们来看看保存的内容,xml/apr_xml.c:35:19: fatal error: expat.h: No such file or directory
大概意思就是没有xml,So我们给它安装一个不就好了?


[root@localhost apr-util-1.6.1]# yum install expat-devel -y
...
Complete!

看来已经安装完成了,我们再来试试吧

[root@localhost apr-util-1.6.1]# make
...
[root@localhost apr-util-1.6.1]# make install
...
[root@localhost apr-util-1.6.1]# cd ..
[root@localhost src]# cd httpd-2.4.41
[root@localhost httpd-2.4.41]# ./configure --prefix=/usr/local/apache --with-apr-util=/usr/local/apr-util --with-apr=/usr/local/apr
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 " -g -O2 -pthread"
  setting CPPFLAGS to " -DLINUX -D_REENTRANT -D_GNU_SOURCE"
  setting LDFLAGS to " "
configure:
configure: Configuring Apache Portable Runtime Utility library...
configure:
checking for APR-util... yes
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking how to run the C preprocessor... gcc -E
checking for gcc option to accept ISO C99... -std=gnu99
checking for pcre-config... false
configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/
pcre安装

大家安装了两个关联软件之后,应该都知道这其中的套路了吧 哈哈哈 那我们接着来

  • 安装解压pcre
[root@localhost src]# tar -xzvf pcre-8.42.tar.gz

在这里插入图片描述

  • 软件配置和系统检查,并指定安装路径
[root@localhost src]# cd pcre-8.42
[root@localhost pcre-8.42]# ./configure --prefix=/usr/local/pcre --with-apr-util=/usr/local/apr-util --with-apr=/usr/local/apr
[root@localhost pcre-8.42]# make
[root@localhost pcre-8.42]# make install

[root@localhost pcre-8.42]# cd ..
[root@localhost src]# cd httpd-2.4.41
[root@localhost httpd-2.4.41]# ./configure --prefix=/usr/local/apache --with-pcre=/usr/local/pcre --with-apr-util=/usr/local/apr-util --with-apr=/usr/local/apr
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值