源碼包編譯apache服務器[多圖/臃腫]


參考資料 :
configure文件


進入 apache 主頁

Paste_Image.png

尋找 apache http server 項目

Paste_Image.png

進入 apache http server 項目主頁

Paste_Image.png

尋找下載地址

Paste_Image.png

使用 wget 命令進行下載

http://mirror.bit.edu.cn/apache//httpd/httpd-2.4.25.tar.bz2
wget http://mirror.bit.edu.cn/apache//httpd/httpd-2.4.25.tar.bz2

下載完成

Paste_Image.png

解壓

tar -jxvf ./httpd-2.4.25.tar.bz2
Paste_Image.png

進入解壓目錄

Paste_Image.png

運行 ./configure , 注意這里因為是源碼包安裝 , 因此需要手工指定安裝路徑

./configure --prefix=/usr/local/apache2
Paste_Image.png

出現報錯

configure: 
checking for APR... no
configure: error: APR not found.  Please read the documentation.

出現報錯 , 缺少 APR , 在 apache 官網下載 APR 并編譯安裝

進入apache官網

Paste_Image.png

進入APR項目主頁

Paste_Image.png

找到下載地址并下載

Paste_Image.png

解壓縮

Paste_Image.png
Paste_Image.png

運行 ./configure , 注意這里因為是源碼包安裝 , 因此需要手工指定安裝路徑

sudo ./configure --prefix=/usr/local/apr && make && sudo make install
Paste_Image.png

安裝完成現在嘗試重新編譯 apache http server

Paste_Image.png
configure: 
checking for APR-util... no
configure: error: APR-util not found.  Please read the documentation.

發現又少了這個包 , 同理去 apache 官網下載

Paste_Image.png

下載完成 , 準備解壓

Paste_Image.png

解壓完成 , 進行編譯

./configure --prefix=/usr/local/apr-util
Paste_Image.png

Applying apr-util hints file rules for x86_64-unknown-linux-gnu
checking for APR... no
configure: error: APR could not be located. Please use the --with-apr option.

提示沒有找到 APR , 并提示讓我們使用 --with-apr 來手動指定 APR 的目錄
之前在安裝 APR 的時候我們手動指定了 APR 的目錄是 : /usr/local/apr
因此重新調整參數 , 重新編譯 :

./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
Paste_Image.png
make && sudo make install

安裝完成

Paste_Image.png

編譯安裝 apr-util 完成 , 重新返回去編譯 apache http server , 同時需要加上 --with-apr 與 --with-apr-util 參數

./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util && make && sudo make install
Paste_Image.png

checking for pcre-config... false
configure: error: pcre-config for libpcre not found. 
PCRE is required and available from http://pcre.org/

發現又缺少一個依賴庫 : PCRE
根據提示繼續進行下載編譯安裝


根據提示進入官網

Paste_Image.png

進入下載地址

Paste_Image.png

找到最新的版本進行下載

ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre2-10.22.zip
Paste_Image.png

解壓

unzip ./unzip pcre2-10.22.zip
Paste_Image.png

進入進行編譯

./configure --prefix=/usr/local/pcre && make && sudo make install
Paste_Image.png

又返回重新編譯 apache http server

./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre && make && sudo make install

有報錯 :

configure: error: Did not find pcre-config script at /usr/local/pcre

既然提示沒有找到這個配置文件 , 我們就到這個目錄下面看看是不是真的沒有這個配置文件

Paste_Image.png

可以看到 , 應該是因為我們編譯安裝的 pcre 版本較高 , 這里將配置文件改名為 prce2-config
既然我們都已經下載了高版本的 prce , 那就試試看看能不能編譯成功唄
如果要正確編譯的話 , 應該是要修改 configure 文件了
我們使用 vim 打開 configure 文件 , 對 pcre-config 這個字符串進行搜索
發現總共有6處 , 因為新版本的 pcre 修改了腳本的文件名 , 我們嘗試在 configure 腳本中對文件名進行替換 , 但是一定要注意在修改之前要對文件進行備份

:%s/pcre-config/pcre2-config/

替換成功后 , 顯示總共有6處被vim替換 , 保存退出 , 然后重新運行剛才的編譯命令 :

./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre && make && sudo make install
Paste_Image.png

又提示找不到 pcre.h 這個文件

util_pcre.c:49:18: fatal error: pcre.h: No such file or directory
compilation terminated.
/home/sun/Desktop/apache2/httpd-2.4.25/build/rules.mk:206: recipe for target 'util_pcre.lo' failed
make[2]: *** [util_pcre.lo] Error 1
make[2]: Leaving directory '/home/sun/Desktop/apache2/httpd-2.4.25/server'
/home/sun/Desktop/apache2/httpd-2.4.25/build/rules.mk:75: recipe for target 'all-recursive' failed
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory '/home/sun/Desktop/apache2/httpd-2.4.25/server'
/home/sun/Desktop/apache2/httpd-2.4.25/build/rules.mk:75: recipe for target 'all-recursive' failed
make: *** [all-recursive] Error 1

那就再看看唄

Paste_Image.png

終于我們在這個目錄找到了類似 pcre.h 的文件 pcre2.h


我們可以根據這條報錯 util_pcre.c:49:18: fatal error: pcre.h: No such file or directory 知道 , 報錯是產生在 util_pcre.c 這個文件中的
我們在 apache http server 源碼包的目錄下對這個文件進行定位

find -name util_pcre.c
Paste_Image.png

對其進行編輯 : (當然記住修改之前備份)

Paste_Image.png

繼續開始工作

./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre && make && sudo make install
Paste_Image.png

T_T 放棄了 ... 還是老老實實裝個低版本的 pcre 好好做人吧...


回滾 :

  1. 恢復 configure
  2. 恢復 ./server/util_pcre.c
  3. 刪除 pcre 安裝目錄 (由于是源碼包安裝 , 因此刪除安裝路徑即可 , 輕松無污漬殘留)
  4. 重新下載低版本 pcre , 進行編譯安裝
  5. 重新編譯 apache http server

好 , 繼續
這次沒有下載 pcre2-xxx , 而是下載了 pcre-8.39.zip

Paste_Image.png
Paste_Image.png

繼續編譯我們的 apache http server

./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre && make && sudo make install
Paste_Image.png

成功了 , 啟動一下試試

sudo /usr/local/apache2/

查看一下IP地址

ifconfig
Paste_Image.png
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容