编译安装apache 2.4.12
一、环境系统:CentOS 6.4x64最小化安装
IP:192.168.3.54
二、下载软件包
apache官网www.apache.org上有提供源码下载
1
# wget http://mirrors.cnnic.cn/apache/httpd/httpd-2.4.12.tar.gz
三、安装
解压并安装
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
# tar xf httpd-2.4.12.tar.gz
# cd httpd-2.4.12
# ./configure \
> --prefix=/usr/local/apache-2.4.12 \
> --enable-deflate \ #压缩
> --enable-expires \ #缓存
> --enable-headers \
> --enable-modules=most \
> --enable-so \
> --with-mpm=worker \ #worker模型
> --enable-rewrite \ #rewrite重写规则
> --with-apr=/usr/local/apr \
> --with-apr-util=/usr/local/apr-util
> --enable-ssl #支持ssl
checking for chosen layout... Apache
checking for working mkdir -p... yes
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
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
configure:
configure: Configuring Apache Portable Runtime library...
configure:
checking for APR... no
configure: error: APR not found.Please read the documentation.
#结果显示我们需要安装apr apr-util,pcre-devel,openssl-devel
#下载apr和apr-util
# wget
# wget http://mirrors.hust.edu.cn/apache//apr/apr-util-1.5.4.tar.gz
#先安装pcre-devel,apr
# yum install pcre-developenssl-devel -y
# tar xf apr-1.5.2.tar.gz
# cd apr-1.5.2
# ./configure --prefix=/usr/local/apr
# make && make install
#安装apr-util
# tar xf apr-util-1.5.4.tar.gz
# cd apr-util-1.5.4
# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
# make && make install
#再次安装httpd
# ./configure --prefix=/usr/local/apache-2.4.12 --enable-deflate --enable-expires --enable-headers --enable-modules=most --enable-so --with-mpm=worker --enable-rewrite --enable-ssl --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util
# make && make install
安装完成后,创建软连接,方便管理
1
# ln -s /usr/local/apache-2.4.12/ /usr/local/apache
创建httpd启动脚本文件,httpd的启动脚本可以将/usr/local/apache/bin/apachectl复制到/etc/init.d目录下。这里我们选择手动创建启动脚本文件
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# vim /etc/init.d/httpd
#!/bin/bash
#
# Startup script for the Apache Web Server
#
# chkconfig: - 85 15
# description: Apache is a World Wide Web server.It is used to serve \
# HTML files and CGI.
# processname: httpd
# pidfile: /usr/local/apache2/logs/httpd.pid
# config: /usr/local/apache2/conf/httpd.conf
# Source function library.
. /etc/rc.d/init.d/functions
if [ -f /etc/sysconfig/httpd ]; then
. /etc/sysconfig/httpd
fi
# This will prevent initlog from swallowing up a pass-phrase prompt if
# mod_ssl needs a pass-phrase from the user.
INITLOG_ARGS=""
# Path to the apachectl script, server binary, and short-form for messages.
apachectl=/usr/local/apache/bin/apachectl
httpd=/usr/local/apache/bin/httpd
pid=$httpd/logs/httpd.pid
prog=httpd
RETVAL=0
# The semantics of these two functions differ from the way apachectl does
# things -- attempting to start while running is a failure, and shutdown
# when not running is also a failure.So we just do it the way init scripts
# are expected to behave here.
start() {
echo -n $"Starting $prog: "
daemon $httpd $OPTIONS
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch /var/lock/subsys/httpd
return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
killproc $httpd
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f /var/lock/subsys/httpd $pid
}
reload() {
echo -n $"Reloading $prog: "
killproc $httpd -HUP
RETVAL=$?
echo
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status $httpd
RETVAL=$?
;;
restart)
stop
start
;;
condrestart)
if [ -f $pid ] ; then
stop
start
fi
;;
reload)
reload
;;
graceful|help|configtest|fullstatus)
$apachectl $@
RETVAL=$?
;;
*)
echo $"Usage: $prog {start|stop|restart|condrestart|reload|status"
echo $"|fullstatus|graceful|help|configtest}"
exit 1
esac
exit $RETVAL
#启动httpd服务
root@httpd ~]# /etc/init.d/httpd start
Starting httpd: AH00557: httpd: apr_sockaddr_info_get() failed for httpd
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1. Set the 'ServerName' directive globally to suppress this message
#提示有FQDN错误,解决如下
# echo "ServerName localhost:80" >>/usr/local/apache/conf/httpd.conf
#重新启动httpd服务
# /etc/init.d/httpd stop
Stopping httpd:
# /etc/init.d/httpd start
Starting httpd:
# netstat -anpt |grep httpd
tcp 0 0 :::80 :::* LISTEN 59398/httpd
在客户端访问httpd服务
通过以上步骤apache已成功安装,服务也正常启动,最后将httpd服务添加到开机自动启动
1
2
3
4
# chkconfig --add httpd
# chkconfig httpd on
# chkconfig |grep http
httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
页:
[1]