httpd-2.4编译安装

Posted by Mathew on 2016-08-21

前面介绍了http的历史以及配置文件,接下来咱们聊聊如何编译安装httpd-2.4。

httpd依赖于apr-1.4+,apr-util-1.4+,[apr-icon]。
apr:apache portable runtime。

CentOS 6默认的是apr-1.3.9,apr-util-1.3.9

编译安装步骤

安装装上1.4+版的apr和apr—util
前提安装开发环境 pcre-devel

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
[root@daniel ~]# yum install pcre-devel -y 
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.btte.net
* epel: mirrors.aliyun.com
* extras: mirror.bit.edu.cn
* updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package pcre-devel.x86_64 0:8.32-15.el7_2.1 will be installed
--> Processing Dependency: pcre(x86-64) = 8.32-15.el7_2.1 for package: pcre-devel-8.32-15.el7_2.1.x86_64
--> Running transaction check
---> Package pcre.x86_64 0:8.32-15.el7 will be updated
---> Package pcre.x86_64 0:8.32-15.el7_2.1 will be an update
--> Finished Dependency Resolution

Dependencies Resolved

=======================================================================================================================================================================
Package Arch Version Repository Size
=======================================================================================================================================================================
Installing:
pcre-devel x86_64 8.32-15.el7_2.1 updates 479 k
Updating for dependencies:
pcre x86_64 8.32-15.el7_2.1 updates 420 k

Transaction Summary
=======================================================================================================================================================================
Install 1 Package
Upgrade ( 1 Dependent package)

Total download size: 899 k
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
(1/2): pcre-8.32-15.el7_2.1.x86_64.rpm | 420 kB 00:00:00
(2/2): pcre-devel-8.32-15.el7_2.1.x86_64.rpm | 479 kB 00:00:00
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 1.0 MB/s | 899 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Updating : pcre-8.32-15.el7_2.1.x86_64 1/3
Installing : pcre-devel-8.32-15.el7_2.1.x86_64 2/3
Cleanup : pcre-8.32-15.el7.x86_64 3/3
Verifying : pcre-8.32-15.el7_2.1.x86_64 1/3
Verifying : pcre-devel-8.32-15.el7_2.1.x86_64 2/3
Verifying : pcre-8.32-15.el7.x86_64 3/3

Installed:
pcre-devel.x86_64 0:8.32-15.el7_2.1

Dependency Updated:
pcre.x86_64 0:8.32-15.el7_2.1

Complete!
[root@daniel ~]#

安装apr

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
[root@daniel apr-1.4.6]# ./configure --prefix=/usr/local/apr 
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
Configuring APR library
Platform: x86_64-unknown-linux-gnu
checking for working mkdir -p... yes
APR Version: 1.4.6
checking for chosen layout... apr
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 for langinfo.h... yes
checking for nl_langinfo... yes
setting have_unicode_fs to "0"
setting apr_has_xthread_files to "0"
setting apr_procattr_user_set_requires_password to "0"
setting apr_thread_func to ""
setting apr_has_user to "1"

Restore user-defined environment settings...
restoring CPPFLAGS to ""
setting EXTRA_CPPFLAGS to "-DLINUX=2 -D_REENTRANT -D_GNU_SOURCE"
restoring CFLAGS to ""
setting EXTRA_CFLAGS to "-g -O2 -pthread"
restoring LDFLAGS to ""
setting EXTRA_LDFLAGS to ""
restoring LIBS to ""
setting EXTRA_LIBS to "-lrt -lcrypt -lpthread"
restoring INCLUDES to ""
setting EXTRA_INCLUDES to ""
configure: creating ./config.status
config.status: creating Makefile
config.status: creating include/apr.h
config.status: creating build/apr_rules.mk
config.status: creating build/pkg/pkginfo
config.status: creating apr-1-config
config.status: creating apr.pc
config.status: creating test/Makefile
config.status: creating test/internal/Makefile
config.status: creating include/arch/unix/apr_private.h
config.status: executing libtool commands
rm: cannot remove `libtoolT': No such file or directory
config.status: executing default commands
[root@daniel apr-1.4.6]# make && make install
# 过程省略
Libraries have been installed in:
/usr/local/apr/lib

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
- add LIBDIR to the `LD_LIBRARY_PATH' environment variable
during execution
- add LIBDIR to the `LD_RUN_PATH' environment variable
during linking
- use the `-Wl,-rpath -Wl,LIBDIR' linker flag
- have your system administrator add LIBDIR to `/etc/ld.so.conf'

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
/usr/bin/install -c -m 644 apr.exp /usr/local/apr/lib/apr.exp
/usr/bin/install -c -m 644 apr.pc /usr/local/apr/lib/pkgconfig/apr-1.pc
for f in libtool shlibtool; do \
if test -f ${f}; then /usr/bin/install -c -m 755 ${f} /usr/local/apr/build-1; fi; \
done
/usr/bin/install -c -m 755 /root/apr-1.4.6/build/mkdir.sh /usr/local/apr/build-1
for f in make_exports.awk make_var_export.awk; do \
/usr/bin/install -c -m 644 /root/apr-1.4.6/build/${f} /usr/local/apr/build-1; \
done
/usr/bin/install -c -m 644 build/apr_rules.out /usr/local/apr/build-1/apr_rules.mk
/usr/bin/install -c -m 755 apr-config.out /usr/local/apr/bin/apr-1-config
[root@daniel apr-1.4.6]#

安装apr-util

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
[root@daniel apr-util-1.4.1]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
checking for a BSD-compatible install... /usr/bin/install -c
checking for working mkdir -p... yes
APR-util Version: 1.4.1
checking for chosen layout... apr-util
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
Applying apr-util hints file rules for x86_64-unknown-linux-gnu
checking for APR... yes
# 过长省略
configure: creating ./config.status
config.status: creating Makefile
config.status: creating export_vars.sh
config.status: creating build/pkg/pkginfo
config.status: creating apr-util.pc
config.status: creating apu-1-config
config.status: creating include/private/apu_select_dbm.h
config.status: creating include/apr_ldap.h
config.status: creating include/apu.h
config.status: creating include/apu_want.h
config.status: creating test/Makefile
config.status: creating include/private/apu_config.h
config.status: executing default commands
[root@daniel apr-util-1.4.1]# make && make install
Making all in xml/expat
make[1]: Entering directory `/root/apr-util-1.4.1/xml/expat'
/bin/sh ./libtool --silent --mode=compile gcc -g -O2 -DHAVE_EXPAT_CONFIG_H -I./lib -I. -o lib/xmlparse.lo -c lib/xmlparse.c
/bin/sh ./libtool --silent --mode=compile gcc -g -O2 -DHAVE_EXPAT_CONFIG_H -I./lib -I. -o lib/xmltok.lo -c lib/xmltok.c
/bin/sh ./libtool --silent --mode=compile gcc -g -O2 -DHAVE_EXPAT_CONFIG_H -I./lib -I. -o lib/xmlrole.lo -c lib/xmlrole.c
/bin/sh ./libtool --silent --mode=link gcc -g -O2 -DHAVE_EXPAT_CONFIG_H -I./lib -I. -no-undefined -version-info 5:0:5 -rpath /usr/local/apr-util/lib -o libexpat.la lib/xmlparse.lo lib/xmltok.lo lib/xmlrole.lo
make[1]: Leaving directory `/root/apr-util-1.4.1/xml/expat'
make[1]: Entering directory `/root/apr-util-1.4.1'
/bin/sh /usr/local/apr/build-1/libtool --silent --mode=compile gcc -g -O2 -pthread -DHAVE_CONFIG_H -DLINUX=2 -D_REENTRANT -D_GNU_SOURCE -I/root/apr-util-1.4.1/include -I/root/apr-util-1.4.1/include/private -I/usr/local/apr/include/apr-1 -I/root/apr-util-1.4.1/xml/expat/lib -o buckets/apr_brigade.lo -c buckets/apr_brigade.c && touch buckets/apr_brigade.lo
/bin/sh /usr/local/apr/build-1/libtool --silent --mode=compile gcc -g -O2 -pthread -DHAVE_CONFIG_H -DLINUX=2 -D_REENTRANT -D_GNU_SOURCE -I/
# 过长省略
Libraries have been installed in:
/usr/local/apr-util/lib

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
- add LIBDIR to the `LD_LIBRARY_PATH' environment variable
during execution
- add LIBDIR to the `LD_RUN_PATH' environment variable
during linking
- use the `-Wl,-rpath -Wl,LIBDIR' linker flag
- have your system administrator add LIBDIR to `/etc/ld.so.conf'

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
/usr/bin/install -c -m 644 aprutil.exp /usr/local/apr-util/lib
/usr/bin/install -c -m 755 apu-config.out /usr/local/apr-util/bin/apu-1-config
[root@daniel apr-util-1.4.1]#

安装httpd2.4

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# groupadd -r apache      # 创建apache组
# useradd -r -g apache apahce # 创建apache用户指定组为apache
# ./configure --prefix=/usr/local/apache --sysconf=/etc/httpd24 --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --enable-modules=most --enable-mpms-shared=all --with-mpm=prefork
# make && make install

# 详细命令执行过程省略

Installing configuration files
mkdir /etc/httpd24
mkdir /etc/httpd24/extra
mkdir /etc/httpd24/original
mkdir /etc/httpd24/original/extra
Installing HTML documents
mkdir /usr/local/apache/htdocs
Installing error documents
mkdir /usr/local/apache/error
Installing icons
mkdir /usr/local/apache/icons
mkdir /usr/local/apache/logs
Installing CGIs
mkdir /usr/local/apache/cgi-bin
Installing header files
mkdir /usr/local/apache/include
Installing build system files
mkdir /usr/local/apache/build
Installing man pages and online manual
mkdir /usr/local/apache/man
mkdir /usr/local/apache/man/man1
mkdir /usr/local/apache/man/man8
mkdir /usr/local/apache/manual
make[1]: Leaving directory `/root/httpd-2.4.6'

启动测试

注意:默认的启动程序在/usr/local/apache/bin/apachectl
编辑配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[root@daniel ~]# cat /etc/profile.d/httpd.sh 
export PATH=/usr/local/apache/bin:$PATH
[root@daniel ~]# which apachectl
/usr/local/apache/bin/apachectl
[root@daniel ~]# apachectl start
httpd (pid 31126) already running
[root@daniel ~]# ss -tnl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 :::80 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 128 *:22 *:*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 100 127.0.0.1:25 *:*
[root@daniel ~]#
# 此时80端口已经监听

访问页面

至此,httpd2.4的编译安装已然完成。