基於Centos6.2的Apache2.4.2編譯安裝

       Apache,目前世界排名第一的web服務器,雖說nginx發展迅猛,但是在一段時間以內還是很難撼動Apache的老大地位的,一直以來都是yum安裝,方便,快速,但是不夠靈活,所以花了點時間編譯安裝體驗一把,遂記錄之,留作以後存檔參考

截止2012819日,Apache的最新版本是2.4.2,而編譯安裝Apache所需的aprapr-util的最新版本分別是apr-1.4.6.tar.gzapr-util-1.4.1.tar.gz

1、首先安裝Apache所需的gcc,一般我們配好yum源,直接yum –y install gcc即可

[root@centos6 ~]# 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、下載所需的軟件包

[root@centos6 src]# pwd

/usr/local/src

[root@centos6 src]# wget http://mirror.bit.edu.cn/apache/httpd/httpd-2.4.2.tar.gz

[root@centos6 src]# wget http://mirror.bit.edu.cn/apache/apr/apr-util-1.4.1.tar.gz

[root@centos6 src]# wget http://mirror.bit.edu.cn/apache/apr/apr-1.4.6.tar.gz

[root@centos6 src]# ls

apr-1.4.6.tar.gz  apr-util-1.4.1.tar.gz  httpd-2.4.2.tar.gz

3、開始編譯安裝

3.1 首先編譯安裝apr-1.4.6

tar zxf apr-1.4.6.tar.gz

   42  cd apr-1.4.6

   43  mkdir /usr/local/apr-1.4.6

   44  ./configure --prefix=/usr/local/apr-1.4.6/

   45  make

   46  make install

   47  history

3.2 編譯安裝apr-util-1.4.1

mkdir /usr/local/apr-util-1.4.1

   49  cd -

   50  tar zxf apr-util-1.4.1.tar.gz

   51  cd 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

   53  make

   54  make install

3.3 編譯安裝Apache2.4.2

[root@centos6       httpd-2.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

   65  ls

   66  cd pcre-8.31

   67  ls

   68  mkdir /usr/local/pcre-8.31

   69  ./configure --prefix=/usr/local/pcre-8.31/

   70  make—編譯失敗,因爲前邊只安裝了gcc,沒有安裝gcc++等軟件包

   71  yum install gcc gcc-c++ gcc-g77

   72  ./configure --prefix=/usr/local/pcre-8.31/

   73  make

   74  make 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/

   78  make

   79  make install

   80  cd ../..

   81  ln -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 in <IfDefine name> directives

  -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)

查看版本及啓動服務

[root@centos6 local]# /usr/local/apache2/bin/apachectl -v

Server version: Apache/2.4.2 (Unix)

Server built:   Aug 19 2012 10:39:28

[root@centos6 local]# /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

沒起來,什麼情況,不急,看下進程

[root@centos6 local]# ps -ef | grep httpd

root     27732     1  0 10:48 ?        00:00:00 /usr/local/httpd-2.4.2//bin/httpd --help

daemon   27733 27732  0 10:48 ?        00:00:00 /usr/local/httpd-2.4.2//bin/httpd --help

daemon   27734 27732  0 10:48 ?        00:00:00 /usr/local/httpd-2.4.2//bin/httpd --help

daemon   27735 27732  0 10:48 ?        00:00:00 /usr/local/httpd-2.4.2//bin/httpd --help

root     27859 24392  0 10:56 pts/0    00:00:00 grep httpd

 

先把進程kill

[root@centos6 local]# ps -ef | grep httpd | awk '{print $2}'| while read line

> do

> kill -9 $line

> done

然後,再修改下配置文件vim /usr/local/apache2/conf/httpd.conf,將ServerName前的“#”去掉~~

再次重啓服務

[root@centos6 local]# /usr/local/apache2/bin/apachectl -k start

[root@centos6 local]#

OK!沒報錯

檢查一下

[root@centos6 ~]# netstat -lnt | grep 80

tcp       0      0 :::80                       :::*                        LISTEN

[root@centos6 ~]# lsof -i tcp:80

COMMAND  PID   USER   FD   TYPE DEVICE SIZE/OFF NODE NAME

httpd   1911   root    4u  IPv6  14787      0t0  TCP *:http (LISTEN)

httpd   1912 daemon    4u  IPv6  14787      0t0  TCP *:http (LISTEN)

httpd   1913 daemon    4u  IPv6  14787      0t0  TCP *:http (LISTEN)

httpd   1942 daemon    4u  IPv6  14787      0t0  TCP *:http (LISTEN)

把防火牆和selinux關掉

瀏覽器訪問

至此,編譯安裝成功!

後續會繼續寫下web優化類的文章!

 

本人水平優先,如有錯誤之處,請提出更正,共同學習,共同進步,謝謝!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章