apache原始碼編譯安裝
阿新 • • 發佈:2018-12-31
原始碼安裝apche
下載apache的原始碼包檔案
訪問
http://mirror.bit.edu.cn/apache/httpd/,複製如下gz檔案的連結地址,並使用wget下載到本地
wget -P /usr/local/src/
http://mirror.bit.edu.cn/apache/httpd/httpd-2.4.37.tar.bz2(各位不要直接複製我的下載地址,因為隨著httpd的版本更新,這些地址會變化的)
[[email protected] ~]# cd /usr/local/src/
[[email protected] src]# ls
httpd-2.4.37.tar.bz2
這時候去解壓,解壓命令:
tar -xvf httpd-2.4.37.tar.bz2
[ [email protected] src]# ls
httpd-2.4.37 httpd-2.4.37.tar.bz2
進入到httpd-2.4.37目錄下執行:./configure
這個時候你就會發現報錯嘍,顯示如下:
[[email protected] httpd-2.4.37]# ./configure
checking for chosen layout... Apache
checking for working mkdir -p... yes
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
configure:
configure: Configuring Apache Portable Runtime library...
configure:
checking for APR... no
configure: error: APR not found. Please read the documentation
好吧,通過提示,我們可以看到缺少APR,接下來去下載APR包
瀏覽器訪問:
http://mirror.bit.edu.cn/apache/apr/,去下載apr包和apr-unit包
wget -P /usr/local/src
http://mirror.bit.edu.cn/apache/apr/apr-1.6.5.tar.bz2
wget -P /usr/local/src
http://mirror.bit.edu.cn/apache/apr/apr-util-1.6.1.tar.bz2
[email protected] apr-1.6.5]# ./configure
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
Configuring APR library
Platform: x86_64-pc-linux-gnu
checking for working mkdir -p... yes
APR Version: 1.6.5
checking for chosen layout... apr
checking for gcc... no
checking for cc... no
checking for cl.exe... no
configure: error: in `/usr/local/src/apr-1.6.5':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details
這個時候又看到報錯啦,好吧,通過提示我們可以看到缺少gcc環境,為此安裝gcc編譯環境
yum install gcc
ok,然後再次去執行./configure
然後編譯安裝:make && make install
[[email protected] apr-1.6.5]# ls /usr/local/apr/
bin build-1 include lib
此時代表安裝成功apr
安裝apr-unit
去apr-unit目錄下去執行./configure
[[email protected] apr-util-1.6.1]# ./configure
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
checking for a BSD-compatible install... /usr/bin/install -c
checking for working mkdir -p... yes
APR-util Version: 1.6.1
checking for chosen layout... apr-util
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
Applying apr-util hints file rules for x86_64-pc-linux-gnu
checking for APR... no
configure: error: APR could not be located. Please use the --with-apr option
好吧,又報錯哈哈,通過提示我們可以看到這是讓我們使用--with-apr引數去指定剛剛安裝完的apr路徑,那麼開始吧
./configure --help去檢視執行命令引數與含義
Optional Packages:
--with-PACKAGE[=ARG] use PACKAGE [ARG=yes]
--without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no)
--with-apr=PATH prefix for installed APR or the full path to apr-config
嗯,現在知道該怎麼寫了,
./configure --with-apr=/usr/local/apr
然後去編譯並安裝
make && make install
好吧,這次在編譯的時候,出現了錯誤,錯誤如下:
xml/apr_xml.c:35:19: 致命錯誤:expat.h:沒有那個檔案或目錄
#include <expat.h>
^
編譯中斷。
make[1]: *** [xml/apr_xml.lo] 錯誤 1
make[1]: 離開目錄“/usr/local/src/apr-util-1.6.1”
make: *** [all-recursive] 錯誤 1
通過報錯分析,應該是缺少expat,好吧,我們百度一下看看這是咋回事呢
解壓所下載的包後,我們先去安裝apr [[email protected] src]# cd apr-1.6.5/ [
那我們知道原因後,就安裝唄 yum install expat-devel 這次編譯安裝過程就舒服多了,最後我們看到如下提示: ---------------------------------------------------------------------- Libraries have been installed in: /usr/local/apr/lib If you ever happen to want to link against installed libraries in a given directory, LIBDIR, you must either use libtool, and specify the full pathname of the library, or use the '-LLIBDIR' flag during linking and do at least one of the following: - add LIBDIR to the 'LD_LIBRARY_PATH' environment variable during execution - add LIBDIR to the 'LD_RUN_PATH' environment variable during linking - use the '-Wl,-rpath -Wl,LIBDIR' linker flag - have your system administrator add LIBDIR to '/etc/ld.so.conf' See any operating system documentation about shared libraries for more information, such as the ld(1) and ld.so(8) manual pages. ---------------------------------------------------------------------- 好吧,一看就知道安裝到/usr/local/apr/lib下了 既然都裝完了,那麼我們去安裝httpd去唄 在httpd下執行./configure 又報錯了: 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沒有安裝啊,嗯,原始碼編譯真煩呢,為啥我不直接yum呢,哈哈 下載PCRE: http://jaist.dl.sourceforge.net/project/pcre/pcre/
下載並解壓: wget -P /usr/local/src/ http://jaist.dl.sourceforge.net/project/pcre/pcre/8.42/pcre-8.42.tar.gz tar -xvf pcre-8.42.tar.gz 進入pcre目錄執行:./configure 檢視執行結果發現,又不稱心如意 configure: error: Invalid C++ compiler or C++ compiler flags 這明顯是還需要gcc-c++環境啊,果斷安裝: yum install gcc-c++ 編譯安裝: make && make install 這次終於可以去httpd目錄執行./configure了吧,然後沒有發現報錯呢 編譯安裝httpd: make && make install 好了,幾經波折,我們去 /usr/local/apache2/bin 目錄下找apachectl 執行啟動指令碼: ./apachectl 檢視程序: [[email protected] bin]# ps -ef|grep httpd root 16123 1 0 17:59 ? 00:00:00 /usr/local/apache2/bin/httpd daemon 16124 16123 0 17:59 ? 00:00:00 /usr/local/apache2/bin/httpd daemon 16125 16123 0 17:59 ? 00:00:00 /usr/local/apache2/bin/httpd daemon 16126 16123 0 17:59 ? 00:00:00 /usr/local/apache2/bin/httpd root 16209 4151 0 17:59 pts/0 00:00:00 grep --color=auto httpd 到此,apache的原始碼安裝結束。 ok,最後我們來總結一下需要用到的原始碼包和編譯環境
apr-1.6.5.tar.bz2
apr-util-1.6.1.tar.bz2
httpd-2.4.37.tar.bz2
pcre-8.42.tar.gz
gcc
gcc-c++
PCRE
expat-devel