从源码包编译安装httpd
在 https://www.cnblogs.com/takenika/articles/18355551 中介绍了 编译安装与make编译的处理流程。
该部分是具体对源码的httpd进行编译。
▶ 下载 httpd 源码包
这首先需要httpd的源码包,这需要去官方进行下载。
源码包的下载地址 ==> https://dlcdn.apache.org/httpd/httpd-2.4.62.tar.gz
这里我下载的是 httpd-2.4.62.tar.gz 软件包,该软件包存在在 /usr/local 目录文件中。
执行上述的操作:
[root@server ~]# cd /usr/local/
[root@server local]# wget https://dlcdn.apache.org/httpd/httpd-2.4.62.tar.gz
--snip--
100%[==============================================>] 9,872,432 73.8KB/s in 2m 14s
[root@server local]# ll httpd-2.4.62.tar.gz
-rw-r--r--. 1 root root 9872432 Jul 17 13:48 httpd-2.4.62.tar.gz
由于make通常需要gcc所以要先安装gcc,否则在后面的make中还会报缺少gcc的问题就像是下面一样
checking for gcc... no
checking for cc... no
checking for cl.exe... no
checking for clang... no
安装 gcc
[root@server httpd-2.4.62]# yum -y install gcc
▶ 准备编译安装
解压 httpd-2.4.62.tar.gz 后,就会得到源码的具体内容。
在源码的 tar.gz包中通常有 INSTALL 的说明文件,该文件会指导使用者进行编译安装。
[root@server local]# tar -xf httpd-2.4.62.tar.gz
[root@server local]# cd httpd-2.4.62/
[root@server httpd-2.4.62]# cat INSTALL
--snip--
For complete installation documentation, see [ht]docs/manual/install.html or
http://httpd.apache.org/docs/2.4/install.html
$ ./configure --prefix=PREFIX
$ make
$ make install
$ PREFIX/bin/apachectl start
--snip--
通过查看 INSTALL 文件,自然就知道了httpd源码如何编译、安装、启动该服务。
./configure --prefix=PREFIX 是配置检查,这是一个执行的脚本为的是检查环境是否符合要求,同时也能自定义一些功能后面的 --prefix=PREFIX 通过阅读 INSTALL 得知了这是 httpd 安装路径的选项,这里将 PREFIX 这一部分改为 /usr/local/apache2,表明在安装 httpd 时候 httpd 会安装在 /usr/local/apache2 这个目录中。
[root@server httpd-2.4.62]# mkdir /usr/local/apache2
[root@server httpd-2.4.62]# ./configure --prefix="/usr/local/apache2"
--snip--
checking for APR... no
configure: error: APR not found. Please read the documentation.
通过检查知道了 ARP 没有被找到,这是因为由于apache应用程序需要做很多的事情,apache只是关注与客户端请求的部分,而 ARP 关注的是与操作系统高级IO功能。
▷▷ 插曲:准备 APR、APR-util 源代码文集
在 https://apr.apache.org/download.cgi 中有相关的下载。
[root@server local]# wget https://dlcdn.apache.org//apr/apr-1.7.4.tar.gz
[root@server local]# wget https://dlcdn.apache.org//apr/apr-util-1.6.3.tar.gz
[root@server local]# ll apr*
-rw-r--r--. 1 root root 1122147 Apr 16 2023 apr-1.7.4.tar.gz
-rw-r--r--. 1 root root 556623 Aug 14 00:45 apr-util-1.6.3.tar.gz
解压后重命名
[root@server local]# tar -xf apr-1.7.4.tar.gz
[root@server local]# tar -xf apr-util-1.6.3.tar.gz
[root@server local]# mv apr-1.7.4 apr
[root@server local]# mv apr-util-1.6.3 apr-util
将 apr、apr-util 存放在 httpd-2.4.39/srclib/。
[root@server local]# mv apr httpd-2.4.62/srclib/
[root@server local]# mv apr-util httpd-2.4.62/srclib/
编译
[root@server local]# ./configure --prefix=/usr/local/apache2 --with-include-apr
--snip--
checking for -pcre2-config... no
checking for -pcre-config... no
checking for pcre2-config... no
checking for pcre-config... no
configure: error: pcre(2)-config for libpcre not found. PCRE is required and available from http://pcre.org/
pcre 是一个库由于这个库没有安装所以,所以配置脚本你报错了,这就需要再安装 pcre 与 pcre-devel 。
[root@server httpd-2.4.62]# yum install pcre
[root@server httpd-2.4.62]# yum install pcre-devel
再次 ./configure。
[root@server httpd-2.4.62]# ./configure --prefix=/usr/local/apache2 --with-include-apr
--snip--
configure: summary of build options:
Server Version: 2.4.62
Install prefix: /usr/local/httpd-2.4.62
C compiler: gcc -std=gnu11
CFLAGS: -g -O2 -pthread
CPPFLAGS: -DLINUX -D_REENTRANT -D_GNU_SOURCE
LDFLAGS:
LIBS:
C preprocessor: gcc -std=gnu11 -E
这就是成功后的显示。
▶ 编译与安装 make与make install
[root@server httpd-2.4.62]# make
--snip--
xml/apr_xml.c:35:19: fatal error: expat.h: No such file or directory
#include <expat.h>
^
compilation terminated.
make[3]: *** [xml/apr_xml.lo] Error 1
make[3]: Leaving directory `/usr/local/httpd-2.4.62/srclib/apr-util'
make[2]: *** [all-recursive] Error 1
make[2]: Leaving directory `/usr/local/httpd-2.4.62/srclib/apr-util'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/usr/local/httpd-2.4.62/srclib'
make: *** [all-recursive] Error 1
这是因为系统缺失 expat 库,还要安装 expat 库 expat-devel。
[root@server httpd-2.4.62]# yum install -y expat-devel
再次 make 编译
[root@server httpd-2.4.62]# ./configure --prefix=/usr/local/apache2 --with-include-apr
--snip--
make[4]: Leaving directory `/usr/local/httpd-2.4.62/modules/mappers'
make[3]: Leaving directory `/usr/local/httpd-2.4.62/modules/mappers'
make[2]: Leaving directory `/usr/local/httpd-2.4.62/modules'
make[2]: Entering directory `/usr/local/httpd-2.4.62/support'
make[2]: Leaving directory `/usr/local/httpd-2.4.62/support'
make[1]: Leaving directory `/usr/local/httpd-2.4.62'
最后 make install
[root@server httpd-2.4.62]# make install
--snip--
mkdir /usr/local/apache2/man
mkdir /usr/local/apache2/man/man1
mkdir /usr/local/apache2/man/man8
mkdir /usr/local/apache2/manual
make[1]: Leaving directory `/usr/local/httpd-2.4.62'
▶ 最后的启动
[root@server httpd-2.4.62]# /usr/local/apache2/bin/apachectl start
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::9aa0:e760:a385:246b%ens33. Set the 'ServerName' directive globally to suppress this message
httpd (pid 119592) already running
客户端的访问:

浙公网安备 33010602011771号