1.下載apache到/usr/local/src/ 並解壓
cd /usr/local/src/
wget http://mirrors.cnnic.cn/apache/httpd/httpd-2.2.31.tar.gz
tar -zxvf httpd-2.2.31.tar.gz
2.配置編譯參數:
cd httpd-2.2.31
./configure \ --prefix=/usr/local/apache \ --with-included-apr \ --enable-so \ --enable-deflate=shared \ --enable-expires=shared \ --enable-rewrite=shared \ --with-pcre
echo $?
顯示0,表示有0個錯誤,每弄一步,必須執行
--prefix 指定安裝到哪裡, --enable-so 表示啟用DSO --enable-deflate=shared 表示共享的方式編譯deflate,後面的參數同理。
configure: error: in `/usr/local/src/httpd-2.2.31/srclib/apr': configure: error: no acceptable C compiler found in $PATH
gcc包沒有安裝
yum install -y gcc
error: Bundled APR requested but not found at ./srclib/. Download and unpack the corresponding apr and apr-util packages to ./srclib/.
解決辦法:
將APR和APR-util源碼下載,解壓放到httpd-2.2.31/srclib裡面,並去除版本號
cd /usr/local/src
wget http://apache.fayea.com/apr/apr-1.5.2.tar.bz2 wget http://apache.fayea.com/apr/apr-util-1.5.4.tar.bz2 tar -jxvf apr-util-1.5.4.tar.bz2 tar -jxvf apr-1.5.2.tar.bz2
cp -rf apr-1.5.2 /usr/local/src/httpd-2.2.31/srclib/apr //將版本號去掉,下同 cp -rf apr-util-1.5.4 /usr/local/src/httpd-2.2.31/srclib/apr-util
configure: error: in `/usr/local/src/httpd-2.2.31/srclib/apr':
configure: error: no acceptable C compiler found in $PATH
執行./configure時,可能會遇到以上錯誤,這個主要是gcc包沒有安裝。對於這個問題,使用yum install -y gcc就可以了。
configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/
這是由於沒有安裝apr 及 apr-util 以及PCRE,因此需要下載安裝,這裡演示的是源碼安裝
wget http://apache.fayea.com/apr/apr-1.5.2.tar.bz2
tar -jxvf apr-1.5.2.tar.bz2
cd apr-1.5.2
./configure -with-apr=/usr/local/apr
make && make install
wget http://apache.fayea.com/apr/apr-util-1.5.4.tar.bz2
tar -jxvf apr-util-1.5.4.tar.bz2
cd apr-util-1.5.4
./configure -with-apr=/usr/local/apr-util
make && make install
wget http://nchc.dl.sourceforge.net/project/pcre/pcre/8.39/pcre-8.39.tar.bz2
tar -jxvf pcre-8.39.tar.bz2
cd pcre-8.39
./configure --prefix=/usr/local/pcre
make && make install
make[1]: *** [pcrecpp.lo] Error 1
說明缺少安裝gcc-c++庫,安裝即可
yum install -y gcc-c++
make[1]: Leaving directory `/usr/local/src/pcre-8.31' 可忽略
rm /usr/local/share/man/man3/pcre* -rf
make clean
make install
configure: error: mod_deflate has been requested but can not be built due to prerequisite failures
那是沒有安裝zlib包
yum install -y zlib-devel
3.make
解決依賴關係
yum -y install pcre pcre-devel
4.make install
啟動apache
/usr/local/apache/bin/apachectl start
如果報錯
httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain for ServerNam
vim /usr/local/apache/conf/httpd.conf
ServerName [email protected]:80 替換為下面的後再啟動
ServerName localhost:80
curl http://localhost:80
顯示it`s ok 表示apache安裝成功並啟動
configure: error: Size of "void *" is less than size of "long"
解決方法:vi configure
if test”$ap_cv_void_ptr_lt_long” =”yes”; then
as_fn_error $? “Size of \”void*\” is less than size of \”long\”” “$LINENO” 5
改為if test”$ap_cv_void_ptr_lt_long” != “yes”; then
as_fn_error $? “Size of \”void*\” is less than size of \”long\”” “$LINENO” 5
保存重新編譯