基于Centos6.2的Apache2.4.2编译安装
Apache,目前世界排名第一的web服务器,虽说nginx发展迅猛,但是在一段时间以内还是很难撼动Apache的老大地位的,一直以来都是yum安装,方便,快速,但是不够灵活,所以花了点时间编译安装体验一把,遂记录之,留作以后存档参考截止2012年8月19日,Apache的最新版本是2.4.2,而编译安装Apache所需的apr和apr-util的最新版本分别是apr-1.4.6.tar.gz,apr-util-1.4.1.tar.gz
1、首先安装Apache所需的gcc,一般我们配好yum源,直接yum –y install gcc即可
# yum install gcc
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
Setting up Install Process
Resolving Dependencies
…………..
…………..
Installed:
gcc.x86_64 0:4.4.6-4.el6
Dependency Installed:
cloog-ppl.x86_64 0:0.15.7-1.2.el6 cpp.x86_64 0:4.4.6-4.el6 glibc-devel.x86_64 0:2.12-1.80.el6_3.4 glibc-headers.x86_64 0:2.12-1.80.el6_3.4
kernel-headers.x86_64 0:2.6.32-279.5.1.el6 mpfr.x86_64 0:2.4.1-6.el6 ppl.x86_64 0:0.10.2-11.el6
Dependency Updated:
glibc.x86_64 0:2.12-1.80.el6_3.4 glibc-common.x86_64 0:2.12-1.80.el6_3.4 libgcc.x86_64 0:4.4.6-4.el6 libgomp.x86_64 0:4.4.6-4.el6
Complete!
2、下载所需的软件包
# pwd
/usr/local/src
# wget http://mirror.bit.edu.cn/apache/httpd/httpd-2.4.2.tar.gz
# wget http://mirror.bit.edu.cn/apache/apr/apr-util-1.4.1.tar.gz
# wget http://mirror.bit.edu.cn/apache/apr/apr-1.4.6.tar.gz
# ls
apr-1.4.6.tar.gzapr-util-1.4.1.tar.gzhttpd-2.4.2.tar.gz
3、开始编译安装
3.1 首先编译安装apr-1.4.6
tar zxf apr-1.4.6.tar.gz
42cd apr-1.4.6
43mkdir /usr/local/apr-1.4.6
44./configure --prefix=/usr/local/apr-1.4.6/
45make
46make install
47history
3.2 编译安装apr-util-1.4.1
mkdir /usr/local/apr-util-1.4.1
49cd -
50tar zxf apr-util-1.4.1.tar.gz
51cd apr-util-1.4.1
52./configure --prefix=/usr/local/apr-util-1.4.1/-with-apr=/usr/local/apr-1.4.6/bin/apr-1-config
53make
54make install
3.3 编译安装Apache2.4.2
#./configure \
--prefix=/usr/local/httpd-2.4.2/ \
-with-apr=/usr/local/apr-1.4.6/ \
-with-apr-util=/usr/local/apr-util-1.4.1/
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
Configuring Apache Portable Runtime library ...
checking for APR... yes
setting CC to "gcc"
setting CPP to "gcc -E"
setting CFLAGS to " -g -O2 -pthread"
setting CPPFLAGS to " -DLINUX=2 -D_REENTRANT -D_GNU_SOURCE"
setting LDFLAGS to " "
Configuring Apache Portable Runtime Utility library...
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最新版本是pcre-8.31,去http://pcre.org下载
ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/
winscp拷贝到Centos6.2/usr/local/src下
unzip -o pcre-8.31.zip
65ls
66cd pcre-8.31
67ls
68mkdir /usr/local/pcre-8.31
69./configure --prefix=/usr/local/pcre-8.31/
70make—编译失败,因为前边只安装了gcc,没有安装gcc++等软件包
71yum install gcc gcc-c++ gcc-g77
72./configure --prefix=/usr/local/pcre-8.31/
73make
74make install
OK!编译安装成功,再次编译安装Apache2.4.2
cd /usr/local/src/httpd-2.4.2
77./configure --prefix=/usr/local/httpd-2.4.2/ -with-apr=/usr/local/apr-1.4.6/ -with-apr-util=/usr/local/apr-util-1.4.1/ -with-pcre=/usr/local/pcre-8.31/
78make
79make install
80cd ../..
81ln -s httpd-2.4.2 apache2
Usage: /usr/local/httpd-2.4.2//bin/httpd [-D name] [-d directory] [-f file]
[-C "directive"] [-c "directive"]
[-k start|restart|graceful|graceful-stop|stop]
[-v] [-V] [-h] [-l] [-L] [-t] [-T] [-S] [-X]
Options:
-D name : define a name for use indirectives
-d directory : specify an alternate initial ServerRoot
-f file : specify an alternate ServerConfigFile
-C "directive" : process directive before reading config files
-c "directive" : process directive after reading config files
-e level : show startup errors of level (see LogLevel)
-E file : log startup errors to file
-v : show version number
-V : show compile settings
-h : list available command line options (this page)
-l : list compiled in modules
-L : list available configuration directives
-t -D DUMP_VHOSTS: show parsed vhost settings
-t -D DUMP_RUN_CFG : show parsed run settings
-S : a synonym for -t -D DUMP_VHOSTS -D DUMP_RUN_CFG
-t -D DUMP_MODULES : show all loaded modules
-M : a synonym for -t -D DUMP_MODULES
-t : run syntax check for config files
-T : start without DocumentRoot(s) check
-X : debug mode (only one worker, do not detach)
查看版本及启动服务
# /usr/local/apache2/bin/apachectl -v
Server version: Apache/2.4.2 (Unix)
Server built: Aug 19 2012 10:39:28
# /usr/local/apache2/bin/apachectl --help
AH00557: httpd: apr_sockaddr_info_get() failed for centos6.2
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
没起来,什么情况,不急,看下进程
# ps -ef | grep httpd
root 27732 10 10:48 ? 00:00:00 /usr/local/httpd-2.4.2//bin/httpd --help
daemon 27733 277320 10:48 ? 00:00:00 /usr/local/httpd-2.4.2//bin/httpd --help
daemon 27734 277320 10:48 ? 00:00:00 /usr/local/httpd-2.4.2//bin/httpd --help
daemon 27735 277320 10:48 ? 00:00:00 /usr/local/httpd-2.4.2//bin/httpd --help
root 27859 243920 10:56 pts/0 00:00:00 grep httpd
先把进程kill掉
# ps -ef | grep httpd | awk '{print $2}'| while read line
> do
> kill -9 $line
> done
然后,再修改下配置文件vim /usr/local/apache2/conf/httpd.conf,将ServerName前的“#”去掉~~
再次重启服务
# /usr/local/apache2/bin/apachectl -k start
#
OK!没报错
检查一下
# netstat -lnt | grep 80
tcp 0 0 :::80 :::* LISTEN
# lsof -i tcp:80
COMMANDPID USER FD TYPE DEVICE SIZE/OFF NODE NAME
httpd 1911 root 4uIPv614787 0t0TCP *:http (LISTEN)
httpd 1912 daemon 4uIPv614787 0t0TCP *:http (LISTEN)
httpd 1913 daemon 4uIPv614787 0t0TCP *:http (LISTEN)
httpd 1942 daemon 4uIPv614787 0t0TCP *:http (LISTEN)
把防火墙和selinux关掉
浏览器访问
file:///C:UsersJIAXIN~1AppDataLocalTempmsohtmlclip11clip_image002.jpg
至此,编译安装成功!
后续会继续写下web优化类的文章!
本人水平优先,如有错误之处,请提出更正,共同学习,共同进步,谢谢!
页:
[1]