释放双眼,带上耳机,听听看~!
最近在玩apache,首先安装apace要配置apr,apr-util,pcre,而配置这些基本都是千篇一律。所谓程序员的精神就是减少重复性的劳动,下面请看我写的apache安装脚本:
这个脚本我也放到我的github上
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 1#!/bin/bash
2# 需要sudo执行
3
4dir=`pwd`
5
6#要安装pcre先要安装 g++
7if [[ `ls /etc|grep redhat-release` != "" ]]
8then
9 yum -y install gcc gcc-c++
10elif [[ `ls /etc|grep debian_version` != "" ]]
11then
12 apt-get -y install gcc gcc-c++
13fi
14
15if [[ `ls|grep apr` == "" ]]
16then
17 wget http://mirrors.cnnic.cn/apache//apr/apr-1.5.2.tar.gz
18fi
19tar -zxvf apr-1.5.2.tar.gz
20mkdir /usr/local/lib/apr-1.5.2
21cd $dir/apr-1.5.2
22./configure --prefix=/usr/local/lib/apr-1.5.2
23make
24make install
25
26cd $dir
27if [[ `ls|grep apr-util` == "" ]]
28then
29 wget http://mirrors.cnnic.cn/apache//apr/apr-util-1.5.4.tar.gz
30fi
31tar -zxvf apr-util-1.5.4.tar.gz
32mkdir /usr/local/lib/apr-util-1.5.4.tar.gz
33cd $dir/apr-util-1.5.4
34./configure --prefix=/usr/local/lib/apr-util-1.5.4 --with-apr=/usr/local/lib/apr-1.5.2
35make
36make install
37
38cd $dir
39if [[ `ls|grep pcre` == "" ]]
40then
41 wget http://ncu.dl.sourceforge.net/project/pcre/pcre/8.37/pcre-8.37.tar.gz
42fi
43tar -zxvf pcre-8.37.tar.gz
44mkdir /usr/local/lib/pcre-8.37
45cd $dir/pcre-8.37
46./configure --prefix=/usr/local/lib/pcre-8.37
47make
48make install
49
50cd $dir
51if [[ `ls|grep httpd` == "" ]]
52then
53 wget http://www.apache.org/dist/httpd/httpd-2.4.12.tar.gz
54fi
55tar -zxvf httpd-2.4.12.tar.gz
56mkdir /usr/local/lib/httpd-2.4.12
57cd $dir/httpd-2.4.12
58./configure --prefix=/usr/local/lib/httpd-2.4.12 --with-apr=/usr/local/lib/apr-1.5.2 --with-apr-util=/usr/local/lib/apr-util-1.5.4 --with-pcre=/usr/local/lib/pcre-8.37 --enable-so
59make
60make install
61
62#解决httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
63
64sed -i 's/^#ServerName www.example.com:80/ServerName localhost/g' /usr/local/lib/httpd-2.4.12/conf/httpd.conf
65
66/usr/local/lib/httpd-2.4.12/bin/apachectl start #启动apache
67if [[ `curl -s localhost:80|grep "It works"` != "" ]]
68then
69 echo "----------------------安装成功-------------------------------------"
70 cd $dir
71 rm -rf apr-1.5.2/ apr-util-1.5.4/ pcre-8.37/ httpd-2.4.12/
72fi
73