參考文章:
http://wenku.baidu.com/view/94e08a20a5e9856a561260e2.html
http://httpd.apache.org/docs/2.4/install.html
工作中需要在MIPS平台的板子上移植apache,折騰一個星期,初步搞定,移植過程記錄如下:
開發機軟硬體平台:
開發板軟硬體平台:
移植的宏觀思路是:
1. 開發機端
1)配置:./configure
2)交叉編譯:make
3)安裝:make install
2. 開發板端
1)下載apache安裝目錄到板子的/usr/local下
2)配置httpd.conf
3)驗證
詳細移植過程如下:
1. 開發機端
1.1配置:./configure
首先指定安裝目錄(prefix),編譯器(CC),平台名(host),庫的路徑(--with-included-apr)
./configure --prefix=/usr/local/apache CC=mips64-octeon-linux-gnu-gcc --host=mips-linux --with-included-apr
提示錯誤:checking for /dev/zero... configure: error: cannot check for file existence when cross compiling
添加配置選項:ac_cv_file__dev_zero=yes
繼續
./configure --prefix=/usr/local/apache CC=mips64-octeon-linux-gnu-gcc --host=mips-linux --with-included-apr ac_cv_file__dev_zero=yes
提示錯誤:checking whether setpgrp takes no argument... configure: error: cannot check setpgrp when cross compiling
添加配置選項:ac_cv_func_setpgrp_void=yes
繼續
./configure --prefix=/usr/local/apache CC=mips64-octeon-linux-gnu-gcc --host=mips-linux --with-included-apr ac_cv_file__dev_zero=yes ac_cv_func_setpgrp_void=yes
錯誤提示:configure: error: cannot run test program while cross compiling
進入./srclib/apr目錄,修改configure檔案,搜尋cannot run test program while cross compiling
一共三處,將中陰影部分注釋掉
繼續
./configure --prefix=/usr/local/apache CC=mips64-octeon-linux-gnu-gcc --host=mips-linux --with-included-apr ac_cv_file__dev_zero=yes ac_cv_func_setpgrp_void=yes
錯誤提示:configure: error: Size of "void *" is less than size of "long"
添加配置參數:ap_cv_void_ptr_lt_long=no
繼續
./configure --prefix=/usr/local/apache CC=mips64-octeon-linux-gnu-gcc --host=mips-linux --with-included-apr ac_cv_file__dev_zero=yes ac_cv_func_setpgrp_void=yes ap_cv_void_ptr_lt_long=no
配置通過
1.2 交叉編譯:make
執行make命令
錯誤提示:/bin/sh: tools/gen_test_char: cannot execute binary file
進入./srclib/apr/tools/
MIPS平台的可執行檔當然不能在X86平台運行,手動產生x86平台的可執行檔,執行
gcc -Wall -O2 -DCROSS_COMPILE gen_test_char.c -s -o gen_test_char
./gen_test_char > ./include/private/apr_escape_test_char.h
修改./srclib/apr/下的Makefile檔案,注釋掉圖示兩行
返回繼續make
錯誤提示:./include/apr_want.h:95: error: redefinition of 'struct iovec'
修改./srclib/apr/include/apr_want.h,注釋掉struct iovec的定義
返回繼續make
錯誤提示:./dftables: ./dftables: cannot execute binary file
進入./srclib/pcre/
執行
gcc -Wall -O2 -DCROSS_COMPILE dftables.c -s -o dftables
返回繼續make
錯誤提示:/bin/sh: ./gen_test_char: cannot execute binary file
進入./server
執行
gcc -Wall -O2 -DCROSS_COMPILE gen_test_char.c -s -o gen_test_char
返回繼續make
錯誤提示:undefined reference to `apr_procattr_limit_set'
好吧,這個錯誤網上查了半天,發現是./configure的時候少了一個配置項,從頭再來吧
make clean
終極配置命令:
./configure --prefix=/usr/local/apache CC=mips64-octeon-linux-gnu-gcc --host=mips-linux --with-included-apr ac_cv_file__dev_zero=yes ac_cv_func_setpgrp_void=yes ap_cv_void_ptr_lt_long=no ac_cv_struct_rlimit=yes
make
編譯通過
1.3 安裝:make install
理論上接下來的動作應該是:make install
但是在make install之前,我要臨時改一下安裝路徑(下面的路徑不固定,可根據自己的需要修改):
export DESTDIR=$NPU_APP_DIR/portable/cavium/execute/local/apache_tmp
然後再
make install
下面講一下原因:
apache依賴三個庫,apr, apr-util, pcre,在httpd-2.2.27版本中,這三個庫的源碼均與apache源碼綁定在一起,在srclib目錄下,編譯apache的時候,這三個庫也一起被編譯了
上面./configure時,我之所以要把安裝目錄指定為/usr/local/apache,是因為我打算把apache的安裝目錄放在板子的/usr/local/apache下,運行/usr/local/apache/bin/httpd時,程式會自動在/usr/local/apache下搜尋依賴的庫檔案。
要產生安裝目錄就必須make install,make install是將源碼目錄下的相應檔案拷貝到安裝目錄下,./configure時我指定的安裝路徑為/usr/local,但是我在開發機上並沒有root許可權,無法寫/usr/local目錄,只能寫我的home目錄(/home/tanghuimin),怎樣臨時修改make install的安裝路徑呢?
查看Makefile檔案,搜尋索引鍵“install”,發現安裝檔案都是放在基於$DESTDIR的路徑下的,那修改$DESTDIR就能修改安裝路徑了,終端下執行
export DESTDIR=$NPU_APP_DIR/portable/cavium/execute/local/apache_tmp
再
make install
$NPU_APP_DIR/portable/cavium/execute/local/apache_tmp/usr/local/apache下便是自動產生的apache安裝目錄了
2 開發板端
2.1 下載apache安裝目錄到板子的/usr/local下
將$NPU_APP_DIR/portable/cavium/execute/local/apache_tmp/usr/local/下的apache目錄打個包,ftp或其他方式,下載到板子的/usr/local/下,解壓,進入/usr/local/apache目錄
2.2 配置httpd.conf
接下來修改相關設定檔:
apache無法以root使用者運行,修改/etc/passwd和/etc/group檔案,新增nobody使用者名稱和nobody工作群組名。
在/etc/passwd中添加一行:
nobody::65534:65533:nobody:/:/bin/sh
在/etc/group中添加:
nobody::65533:
nogroup::65534:nobody
修改/usr/local/apache/conf/httpd.conf檔案
1)修改使用者名稱和使用者組名為nobody
2)修改ServerName為板子的ip地址,我的為192.168.15.29
3)修改監聽連接埠,我的為8080
2.3 驗證
在瀏覽器視窗輸入網址:http://192.168.15.29:8080/
成功!
後記:曾經試過http 2.4.9的移植,但因為在2.4.9版本中,三個庫(apr,apr-util, pcre)的源碼沒有包含在http源碼中,需要外部安裝,而我又沒有開發機的root許可權,導致移植過程中有些動作沒有辦法完成,故轉向低版本的http 2.2.7,http 2.2.7源碼中包含了三個庫檔案的源碼,無需外部安裝庫檔案。
附件:
MIPS平台移植apache_2_2_7.zip
草稿_MIPS平台移植apache_2_4_9.zip