CentOS 5.5下LAMP环境搭建之源码安装Apache2(httpd-2.4.3)
由于安装CentOS5.5的设置可能不一样,所以有些软件在系统安装时就顺便安装了。下面的步骤仅供参考。
1、软件准备
apr-1.4.6.tar.gz (http://apr.apache.org/download.cgi)
apr-util-1.5.1.tar.gz (http://apr.apache.org/download.cgi)
httpd-2.4.3.tar.gz (http://httpd.apache.org/download.cgi)
pcre-8.31.tar.gz (http://www.pcre.org/, http://sourceforge.net/projects/pcre/files/pcre/8.31/)
2、编译工具准备
安装gcc、gcc-c++
[root@localhost ~]# yum install gcc gcc-c++
3、查询和删除系统安装的httpd或apache
[root@localhost ~]# rpm -q httpd apache
httpd-2.2.3-43.el5.centos
package apache is not installed
[root@localhost ~]# yum erase httpd
4、安装依赖的库
(1)解压放置apr和apr-util的源码
将apr-1.4.6.tar.gz、apr-util-1.5.1.tar.gz和httpd-2.4.3.tar.gz解压到/usr/local/src目录下
[root@localhost src]# pwd
/usr/local/src
[root@localhost src]# tar -zxf apr-1.4.6.tar.gz
[root@localhost src]# tar -zxf apr-util-1.5.1.tar.gz
[root@localhost src]# tar -zxf httpd-2.4.3.tar.gz
将apr和apr-util移动到httpd-2.4.3的srclib目录,并去掉版本号
[root@localhost src]# mv apr-1.4.6 httpd-2.4.3/srclib/apr
[root@localhost src]# mv apr-util-1.5.1 httpd-2.4.3/srclib/apr-util
(2)编译安装pcre
[root@localhost src]# tar -zxf pcre-8.31.tar.gz
[root@localhost src]# cd pcre-8.31
[root@localhost pcre-8.31]# ./configure --prefix=/usr/local/pcre
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
……
pcre-8.31 configuration summary:
Install prefix .................. : /usr/local/pcre
C preprocessor .................. : gcc -E
C compiler ...................... : gcc
C++ preprocessor ................ : g++ -E
C++ compiler .................... : g++
Linker .......................... : /usr/bin/ld
C preprocessor flags ............ :
C compiler flags ................ : -O2
C++ compiler flags .............. : -O2
Linker flags .................... :
Extra libraries ................. :
Build 8 bit pcre library ........ : yes
Build 16 bit pcre library ....... : no
Build C++ library ............... : yes
Enable JIT compiling support .... : no
Enable UTF-8/16 support ......... : no
Unicode properties .............. : no
Newline char/sequence ........... : lf
\R matches only ANYCRLF ......... : no
EBCDIC coding ................... : no
Rebuild char tables ............. : no
Use stack recursion ............. : yes
POSIX mem threshold ............. : 10
Internal link size .............. : 2
Match limit ..................... : 10000000
Match limit recursion ........... : MATCH_LIMIT
Build shared libs ............... : yes
Build static libs ............... : yes
Use JIT in pcregrep ............. : no
Buffer size for pcregrep ........ : 20480
Link pcregrep with libz ......... : no
Link pcregrep with libbz2 ....... : no
Link pcretest with libedit ...... : no
Link pcretest with libreadline .. : no
[root@localhost pcre-8.31]# make && make install
rm -f pcre_chartables.c
ln -s ./pcre_chartables.c.dist pcre_chartables.c
make all-am
make[1]: Entering directory `/usr/local/src/pcre-8.31'
……
make[3]: Leaving directory `/usr/local/src/pcre-8.31'
make[2]: Leaving directory `/usr/local/src/pcre-8.31'
make[1]: Leaving directory `/usr/local/src/pcre-8.31'
[root@localhost pcre-8.31]# ls -l /usr/local/pcre
total 16
drwxr-xr-x 2 root root 4096 Oct 29 01:32 bin
drwxr-xr-x 2 root root 4096 Oct 29 01:32 include
drwxr-xr-x 3 root root 4096 Oct 29 01:32 lib
drwxr-xr-x 4 root root 4096 Oct 29 01:32 share
5、编译安装apache(httpd-2.4.3)
[root@localhost httpd-2.4.3]# ./configure --prefix=/usr/local/apache2 --with-included-apr --with-pcre=/usr/local/pcre
checking for chosen layout... Apache
checking for working mkdir -p... yes
……
config.status: creating build/config_vars.sh
config.status: creating include/ap_config_auto.h
config.status: executing default commands
[root@localhost httpd-2.4.3]# make && make install
Making all in srclib
make[1]: Entering directory `/usr/local/src/httpd-2.4.3/srclib'
Making all in apr
……
mkdir /usr/local/apache2/man
mkdir /usr/local/apache2/man/man1
mkdir /usr/local/apache2/man/man8
mkdir /usr/local/apache2/manual
make[1]: Leaving directory `/usr/local/src/httpd-2.4.3'
[root@localhost httpd-2.4.3]# cd /usr/local/apache2/bin
[root@localhost bin]# ./apachectl -k start
6、测试
用浏览器打开http://localhost,看apache是否能访问,如下
参考资料:
1、http://httpd.apache.org/docs/2.4/install.html
2、http://shenlan.blog.51cto.com/55742/458848
3、http://stackoverflow.com/questions/10663180/http-install-error-in-libpcre