編譯環境:
1.linux 主機:fedora7
2.開發板體繫結構: mips
3.交叉編譯器:gcc.3.4.2
4.交叉編譯器目錄:/opt/gcc342
5.軟體版本:httpd-2.2.13.tar.gz
apach2編譯和安裝:
1.configure
CC=/opt/gcc342/bin/mipsel-linux-gcc CPP=/opt/gcc342/bin/mipsel-linux-cpp LD=/opt/gcc342/bin/mipsel-linux-ld AR=/opt/gcc342/bin/mipsel-linux-ar OBJDUMP=/opt/gcc342/bin/mipsel-linux-objdump AS=/opt/gcc342/bin/mipsel-linux-as STRIP=/opt/gcc342/bin/mipsel-linux-strip ./configure --host=mipsel-linux --target=mipsel-linux --build=i686-pc-linux-gnu --prefix=/uer/local/apache2 --with-program-name=apache2 --enable-module=so --enable-module=rewrite --enable-shared=max
在上面命令中:
1)交叉編譯器的一些環境變數的設定:CC=/opt/gcc342/bin/mipsel-linux-gcc CPP=/opt/gcc342/bin/mipsel-linux-cpp LD=/opt/gcc342/bin/mipsel-linux-ld AR=/opt/gcc342/bin/mipsel-linux-ar OBJDUMP=/opt/gcc342/bin/mipsel-linux-objdump AS=/opt/gcc342/bin/mipsel-linux-as STRIP=/opt/gcc342/bin/mipsel-linux-strip ./conf 是對交叉編譯器的一些環境變數的設定。
2)交叉編譯的設定:--host=mipsel-linux --target=mipsel-linux --build=i686-pc-linux-gnu;
--host = 軟體在什麼平台下運行,(你的開發板的系統)host= 架構-廠商-核心-標準庫(mipsel-linux 表示 mips架構,unknow廠商,linux核心,gnu glibc 標準庫。)
--target = 軟體為什麼平台服務
--build = 軟體在什麼平台下編譯(你編譯目標檔案的系統)
3)apache2配置:
--with-program-name=apache2 更改產生的檔案名稱,預設為httpd。
--enable-module=so 用來提DSO支援的apache核心模組,這個比較重要,以便以後安裝動態模組,後面的php5就是安裝的動態模組 。
--enable-module=rewrite rewrite模組則是用來實現地址修正的模組,由於rewrite模組需要DBM支援,如果在初次安裝時沒有編譯進apache,以後需要用到時需要重新編譯整個apache才可以實現。為此除非你可以確定以後不會用到rewrite模組,否則還是建議你在第一次編譯的時候把rewrite模組編譯好。
--enable-shared=max 這個參數的作用時編譯apache時,把除了so以外的所有apache的標準模組都編譯成DSO模組。而不是編譯進apache核心內。
2.編譯並安裝
make;
make install;
3.將/uer/local/apache2目錄拷貝到目標板的檔案系統目錄下,去處沒用的檔案。其實檔案都是有用的,只是目標板太小,只好刪掉。
保留bin/apache2 conf/ module/ lib/ htdocs/檔案就可以了,另外看看conf/apache2.conf中的設定是不是想要的。
4. 在目標板上啟動
/uer/local/apache2/bin/apache -k start
5.在瀏覽器中輸入本地地址,出現“it work !”,說明配置成功。
6.出現的錯誤:
1)./configure過程中,出現configure: error: cannot check for file existence when cross compiling等,具體原因沒找,應該是交叉編譯導致的。
解決:在相應目錄下找到出錯的地方,去掉{ (exit 1); exit 1; };我的問題一般出現在srclib/apr/configure
2)編譯:
a. ./include/apr_want.h:93: error: redefinition of `struct iovec'
解決:在 srclib/apr/include/apr_want.h中,注掉struct iovec
b. ./dftables: cannot execute binary file
解決:因為交叉編譯出的檔案不能在編譯的主機上執行,所以編譯一個本地版本的dftables檔案覆蓋srclib/pcre/dftables
c. ./gen_test_char: cannot execute binary file
同上
d. undefined reference to `pthread_sigmask'
解決:在build/config_var.mk裡AR_LIBS變數加-lpthread
3)啟動
a. 找不到檔案之類
解決:在/usr/local/apache2/conf/apache2.conf中找設定的路徑是否正確,或檔案是否存在。
b. apache2: bad user name daemon
解決:執行adduser daemon
c."apache2: apr_sockaddr_info_get() failed for (none)
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName"
將/usr/local/apache2/conf/apache2.conf檔案中的#ServerName www.example.com:80替換為ServerName localhost:80
d.“(125)Address already in use: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down"
80連接埠正在使用,說明已經有httpd了
PHP5的編譯和安裝:
1.configue
CC=/opt/gcc342/bin/mipsel-linux-gcc CPP=/opt/gcc342/bin/mipsel-linux-cpp LD=/opt/gcc342/bin/mipsel-linux-ld AR=/opt/gcc342/bin/mipsel-linux-ar OBJDUMP=/opt/gcc342/bin/mipsel-linux-objdump AS=/opt/gcc342/bin/mipsel-linux-as STRIP=/opt/gcc342/bin/mipsel-linux-strip ./configure --host=mipsel-linux --target=mipsel-linux --build=i686-pc-linux-gnu --prefix=/uer/local/PHP5 --without-iconv --disable-all --with-apxs2=/usr/local/apache2/bin/apxs
--with-apxs2=/usr/local/apache2/bin/apxs 表示php5 為 Apache 共用模組安裝
2.編譯並安裝
make;
make install;
如果安裝成動態庫,只要將libphp5.so拷貝到/usr/local/apache2/modules就可以了,如果用cli或cgi模式,可能還需要php和php-cgi
3.修改 /usr/local/apache2/conf/apache2.conf檔案
在# LoadModule foo_module modules/mod_foo.so後添加
LoadModule php5_module modules/libphp5.so
在中添加
AddType application/x-httpd-php .php
4.在htdocs/下添加index.php,輸入
5. 重新啟動apache2,它將支援vphp
6.在瀏覽器查看index.php
7.出現的錯誤:
1)error: impossible constraint in `asm'
交叉編譯環境錯誤,將include頭設定為主機路徑(如-I/usr/include),應該是交叉編譯器的頭(如-I/opt/gcc342/include);用--with-iconv=shared,/opt/gcc342/
2)undefined reference to `php_load_extension'
是在 configure時,如果為交叉編譯,她將dlopen設定為no found,只須將found=no去掉。
3)出現Syntax error on line 53 of /usr/local/apache2/conf/apache2.conf: Cannot load /usr/local/apache2/modules/libphp5.so into server: File not found
a./usr/local/apache2/conf/apache2.conf中 LoadModule php5_module modules/libphp5.so目錄路徑不對
b.由2)導致的