參考文章:
http://wenku.baidu.com/view/94e08a20a5e9856a561260e2.html
http://httpd.apache.org/docs/2.4/install.html
工作中需要在MIPS平臺的板子上移植apache,折騰一個星期,初步搞定,移植過程記錄如下:
開發機軟硬件平臺:
開發板軟硬件平臺:
移植的宏觀思路是:
1.開發機端
1)配置:./configure
2)交叉編譯:make
3)安裝:makeinstall
2.開發板端
1)下載apache安裝目錄到板子的/usr/local下
2)配置httpd.conf
3)驗證
詳細移植過程如下:
1.開發機端
1.1配置:./configure
首先指定安裝目錄(PRefix),編譯器(CC),平臺名(host),庫的路徑(--with-included-apr)
./configure--prefix=/usr/local/apacheCC=mips64-octeon-linux-gnu-gcc--host=mips-linux--with-included-apr
提示錯誤:checkingfor/dev/zero...configure:error:cannotcheckforfileexistencewhencrosscompiling
添加配置選項:ac_cv_file__dev_zero=yes
繼續
./configure--prefix=/usr/local/apacheCC=mips64-octeon-linux-gnu-gcc--host=mips-linux--with-included-aprac_cv_file__dev_zero=yes
提示錯誤:checkingwhethersetpgrptakesnoargument...configure:error:cannotchecksetpgrpwhencrosscompiling
添加配置選項:ac_cv_func_setpgrp_void=yes
繼續
./configure--prefix=/usr/local/apacheCC=mips64-octeon-linux-gnu-gcc--host=mips-linux--with-included-aprac_cv_file__dev_zero=yesac_cv_func_setpgrp_void=yes
錯誤提示:configure:error:cannotruntestprogramwhilecrosscompiling
進入./srclib/apr目錄,修改configure文件,搜索cannotruntestprogramwhilecrosscompiling
一共三處,將下圖中陰影部分注釋掉
繼續
./configure--prefix=/usr/local/apacheCC=mips64-octeon-linux-gnu-gcc--host=mips-linux--with-included-aprac_cv_file__dev_zero=yesac_cv_func_setpgrp_void=yes
錯誤提示:configure:error:Sizeof"void*"islessthansizeof"long"
添加配置參數:ap_cv_void_ptr_lt_long=no
繼續
./configure--prefix=/usr/local/apacheCC=mips64-octeon-linux-gnu-gcc--host=mips-linux--with-included-aprac_cv_file__dev_zero=yesac_cv_func_setpgrp_void=yesap_cv_void_ptr_lt_long=no
配置通過
1.2交叉編譯:make
執行make命令
錯誤提示:/bin/sh:tools/gen_test_char:cannotexecutebinaryfile
進入./srclib/apr/tools/
MIPS平臺的可執行文件當然不能在X86平臺運行,手動生成x86平臺的可執行文件,執行
gcc-Wall-O2-DCROSS_COMPILEgen_test_char.c-s-ogen_test_char
./gen_test_char>./include/private/apr_escape_test_char.h
修改./srclib/apr/下的Makefile文件,注釋掉圖示兩行
返回繼續make
錯誤提示:./include/apr_want.h:95:error:redefinitionof'structiovec'
修改./srclib/apr/include/apr_want.h,注釋掉structiovec的定義
返回繼續make
錯誤提示:./dftables:./dftables:cannotexecutebinaryfile
進入./srclib/pcre/
執行
gcc-Wall-O2-DCROSS_COMPILEdftables.c-s-odftables
返回繼續make
錯誤提示:/bin/sh:./gen_test_char:cannotexecutebinaryfile
進入./server
執行
gcc-Wall-O2-DCROSS_COMPILEgen_test_char.c-s-ogen_test_char
返回繼續make
錯誤提示:undefinedreferenceto`apr_procattr_limit_set'
好吧,這個錯誤網上查了半天,發現是./configure的時候少了一個配置項,從頭再來吧
makeclean
終極配置命令:
./configure--prefix=/usr/local/apacheCC=mips64-octeon-linux-gnu-gcc--host=mips-linux--with-included-aprac_cv_file__dev_zero=yesac_cv_func_setpgrp_void=yesap_cv_void_ptr_lt_long=noac_cv_struct_rlimit=yes
make
編譯通過
1.3安裝:makeinstall
理論上接下來的動作應該是:makeinstall
但是在makeinstall之前,我要臨時改一下安裝路徑(下面的路徑不固定,可根據自己的需要修改):
exportDESTDIR=$NPU_APP_DIR/portable/cavium/execute/local/apache_tmp
然后再
makeinstall
下面講一下原因:
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下搜尋依賴的庫文件。
要生成安裝目錄就必須makeinstall,makeinstall是將源碼目錄下的相應文件拷貝到安裝目錄下,./configure時我指定的安裝路徑為/usr/local,但是我在開發機上并沒有root權限,無法寫/usr/local目錄,只能寫我的home目錄(/home/tanghuimin),怎樣臨時修改makeinstall的安裝路徑呢?
查看Makefile文件,搜索關鍵字“install”,發現安裝文件都是放在基于$DESTDIR的路徑下的,那修改$DESTDIR就能修改安裝路徑了,終端下執行
exportDESTDIR=$NPU_APP_DIR/portable/cavium/execute/local/apache_tmp
再
makeinstall
$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
新聞熱點
疑難解答