基於loongson1b開發板(mips架構)移植apache+sqlite3+php5
環境
編譯平臺:Ubuntu12.04
交叉工具鏈:gcc-3.4.6
一、移植Sqlite
解壓Sqlite-3.6.20.tar.gz 到工具目錄下:tar zxf Sqlite-3.6.20.tar.gz -C /home/xxx/tools
進入sqlite-3.6.20目錄中:cd sqlite-3.6.20
1):./configure --host=mipsel-linux(指定交叉編譯工具鏈) --prefix=/opt/mispel-linux-sqlite
2) make
3) make install
在執行make中會出現下面錯誤:
libtool: link: mipsel-linux-gcc -shared .libs/tclsqlite.o -Wl,-rpath -Wl,/opt/sqlite-3.6.20-embedded/.libs -Wl,-rpath -Wl,/opt/mipsel-linux-sqlite/lib ./.libs/libsqlite3.so -L/opt/tcl8.5.15/unix -ltclstub8.5 -lpthread -Wl,-soname -Wl,libtclsqlite3.so -o .libs/libtclsqlite3.so/opt/gcc-4.3-ls232-softfloat/lib/gcc/mipsel-linux/4.3.0/../../../../mipsel-linux/bin/ld: skipping incompatible /opt/gcc-4.3-ls232-softfloat/lib/gcc/mipsel-linux/4.3.0/../../../../mipsel-linux/lib/libtclstub8.5.a when searching for -ltclstub8.5/opt/gcc-4.3-ls232-softfloat/lib/gcc/mipsel-linux/4.3.0/../../../../mipsel-linux/bin/ld: cannot find -ltclstub8.5collect2: ld returned 1 exit statusmake: *** [libtclsqlite3.la] 錯誤
出現:skipping incompatible 一般是不同處理器架構引用了不屬於自己處理器架構的庫,
上面出現的情況,就是mipsel架構的引用了x86架構的庫 libtclstub8.5。
所以要原始碼交叉編譯tclsh才能解決上述問題。
解決方法:解壓tcl8.5.15-src.tar.gz,並進入原始碼資料夾tcl8.5.15
執行:
1)./configure --host=mipsel-linux --prefix=/opt/mipsel-linux-tclsh
2) make
3) make install
但在 ./configure --host=mipsel-linux --prefix=/opt/mipsel-linux-tclsh
過程中會出現以下錯誤:
fixstrtod.o: In function `fixstrtod':fixstrtod.c:(.text+0x0): multiple definition of `fixstrtod'strtod.o:strtod.c:(.text+0x0): first defined herecollect2:
ld returned 1 exit statusmake: *** [libtcl8.5.so] 錯誤 1
執行下面語句:
[root@CaM/opt/tcl-embedded/unix 11:45]#export ac_cv_func_strtod=yes
[root@CaM/opt/tcl-embedded/unix 11:46]#export tcl_cv_strtod_buggy=1
就可以解決了。
編譯安裝完成後,在mipsel-linux-sqlite目錄下分別生成bin、include和lib目錄。
將bin/sqlite3與lib/libsqlite3.so.0.8.6分別拷至檔案系統/bin目錄與/lib目錄下,
並將libsqlite3.so.0.8.6更名為libsqlite3.so.0完成移植。
二、移植apache
$ su (切換到root使用者)
1. 本機編譯
$ cd /usr/local/apache-pc/apache_1.3.39
$ ./configure
錯誤提示:
Configuring for Apache, Version 1.3.39+ Warning: Your ‘echo’ command is slightly broken.+ It interprets escape sequences per default. We already+ tried ‘echo -E’ but had no real success. If errors occur+ please set the SEO variable in ‘configure’ manually to+ the required ‘echo’ options, i.e. those which force your+ ‘echo’ to not interpret escape sequences per default.+ using installation path layout: Apache (config.layout)Creating MakefileCreating Configuration.apaci in srcSyntax error — The configuration file is used only todefine the list of included modules or to set Makefile in srcoptions or Configure rules, and I don’t see that at all:`$(SRCDIR)/apaci`defaultdefaultnononoyesnodefaultnodefaultdefault
解決:
這是由於某些shell指令碼檔案使用了錯誤的interpreter,使用下面的命令就可以解決。
# rm -f /bin/sh# ln -s /bin/bash /bin/sh
$ make
錯誤提示:
解決:
將提示的c檔案中衝突的函式另改別名:如getline 改成get_line,總共有三個c檔案要改。
執行完make後就完成本機編譯了,生成了我們需要使用的編譯工具。
、2. 交叉編譯
(注意交叉工具鏈的環境)
$ cd /usr/local/apache-mipsel/apache_1.3.39
$ CC=mipsel-linux-gcc ./configure --prefix=/usr/local/apache-php/apache --enable-module=so
接著如下修改:cp /usr/local/apache-pc/apache-1.3.39/src/main/gen_test_char /usr/local/apache-pc/apache-1.3.39/src/main/gen_uri_delims /usr/local/apache-mipsel/apache-1.3.39/src/main/
$ make
錯誤提示:
解決:
$ cp /usr/local/apache-pc/apache_1.3.39/src/main/gen_test_char /usr/local/apache-pc/apache_1.3.39/src/main/gen_uri_delims /usr/local/apache-mipsel/apache_1.3.39/src/main/
$ make install
如圖所示,則安裝成功
檢視是否為交叉編譯檔案
$ file /usr/local/apache-php/apache/bin/httpd
三、移植PHP
1. 本地編譯php
$ cd /usr/local/apache-pc/php-5.2.0
$ ./configure
錯誤提示 :
解決 :
sudo apt-get install flex
錯誤提示2 :
解決 :
sudo apt-get install libxml2-dev
$ make
2. 交叉編譯
安裝zlib-1.2.3
$ cd /usr/local/apache-mipsel/zlib-1.2.3
$ CC=mipsel-linux-gcc ./configure --prefix=/usr/local/apache-php/zlib
$ make
$ make install
$ cd /usr/local/apache-mipsel/php-5.2.0
$ CC=mipsel-linux-gcc ./configure --host=mipsel-linux
--prefix=/usr/local/apache-php/php --with-apxs=/usr/local/apache-php/apache/bin/apxs --enable-pdo=shared --with-sqlite=shared --with-pdo-sqlite=shared --with-zlib --with-zlib-dir=/usr/local/apache-php/zlib --without-iconv
錯誤提示1:
解決:
開啟指令碼/usr/local/apache-mipsel/php-5.2.0/configure搜尋“$APXS -q
CFLAGS >/dev/null 2>&1”進行如下程式碼的註釋。
錯誤提示2:
解決 :
安裝libxml2-2.6.11
$ cd libxml2-2.6.11
$ CC=mipsel-linux-gcc ./configure --host=mipsel-linux --prefix=/usr/local/apache-php/zlib
$ make
$ make install
./configure後
首先修改php的Makefile在開始出新增LDFLAGS += -ldl ,這裡是為了連結dlopen庫
然後修改main/php.h 在開始處新增#define HAVE_LIBDL 1 ,這個巨集是為了交叉編譯時強制使用dlopen。
緊接著修改ext/standard/dl.c 這段程式碼中新增#include <dlfcn.h> 這個是dlopen的頭文
件。
#if defined(HAVE_LIBDL) || HAVE_MACH_O_DYLD_H
#include <stdlib.h>
#include <stdio.h>
#include <dlfcn.h>
最後修改 sapi/apache/php_apache_http.h
#include "httpd.h"
#include "http_config.h"
# include "ap_compat.h"
# include "compat.h"
#include "http_core.h"
#include "http_main.h"
#include "http_protocol.h"
#include "http_request.h"
#include "http_log.h"
#include "util_script.h"
將其修改為#include "/usr/local/apache-php/apache/include/httpd.h"這個路徑(這些標頭檔案的目錄)
# make (時間有點長,去喝杯水休息一下吧0﹏0!!)
錯誤提示1:
解決:
修改mod_php5.c中23行錯誤標頭檔案加上/usr/local/apache-arm11/apache/include路徑
錯誤提示2 :
解決:
$ cp /opt/gcc-3.4.6-2f/lib/libxml2.so /us r/lib/i386-linux-gnu/
錯誤提示3: :
解決 :
暫時不知道哪裡出了問題,只能註釋了其中的程式碼
$ make install
錯誤提示 1 :
解決 :
$mv /usr/local/apache-php/apche/bin/httpd /usr/local/apache-php/apache/bin/httpd_backup
$ cp /usr/local/apache-pc/apache/bin/http /usr/local/apache-php/apache/bin/httpd
錯誤提示2 :
解決 :
$mv /usr/local/apache-mipsel/php-5.2.0/sapi/cli/php /usr/local/apache-mipsel/php-5.2.0/sapi/cli/php_backup
$ cp /usr/local/apache-pc/php-5.2.0/sapi/cli/php /usr/local/apache-mipsel/php-5.2.0/sapi/cli/
不出意外應該成功了,可以去/usr/local/apache-php/php/看下是否有目錄
把原來的mips版的php、httpd還原回去 :
cp /usr/local/apache-mips/php-5.2.0/scpi/cli/php_backup /usr/local/apache-php/php/bin/
cp /usr/local/apache-mips/apache/bin/httpd_backup /usr/local/apache-php/apache/bin/httpd
四、配置httpd.conf和php.ini
l 修改httpd.conf
$ vim /usr/local/apache-php/apache/conf/httpd.conf 新增紅色部分
#
# DirectoryIndex: Name of the file or files to use as a pre-written HTML
# directory index. Separate multiple entries with spaces.
#
<IfModule mod_dir.c>
DirectoryIndex index.html
DirectoryIndex index.php
DirectoryIndex index.php3
DirectoryIndex index.phtml
</IfModule>
#
# AccessFileName: The name of the file to look for in each directory
# for access control information.
#
AccessFileName .htaccess
...
# documents in the realname directory are treated as applications and
# run by the server when requested rather than as documents sent to the client.
# The same rules about trailing "/" apply to ScriptAlias directives as to
# Alias.
#
ScriptAlias /cgi-bin/ "/usr/local/apache-php/apache/cgi-bin/"
ScriptAlias /php5/ "/usr/local/apache-php/php/bin/"
#
# "/usr/local/apache-php/apache/cgi-bin" should be changed to whatever your ScriptAliased
# CGI directory exists, if you have that configured.
...
#
# AddType allows you to tweak mime.types without actually editing it, or to
# make certain files to be certain types.
#
AddType application/x-tar .tgz
AddType application/x-httpd-php .php3
AddType application/x-httpd-php .php
AddType application/x-httpd-php .phtml
#
# AddEncoding allows you to have certain browsers uncompress
# information on the fly. Note: Not all browsers support this.
# Despite the name similarity, the following Add* directives have nothing
l 修改php.ini
$ cp /usr/local/apache-mips/php-5.2.0/php.ini-dist /usr/local/apache-php/php/lib/
$ mv /usr/local/apache-php/lib/php.ini-dist /usr/local/apache-php/lib/php.int
$ vim /usr/local/apache-php/lib/php.int
; to possible security problems, if the code is not very well thought of.
register_globals = On
; Whether or not to register the old-style input arrays, HTTP_GET_VARS
; and friends. If you're not using them, it's recommended to turn them off,
五、移植至loongson1B
ps進過九九八十一難終於可以燒進板啦
1、打包apache和php
# tar cjf apache-php.tar.bz2 apache-php
2、經nfs共享至開發板
3、開發板建立/usr/local/
4、解壓至/usr/local/ :與宿主機一致
5、進入/usr/local/apache-php/apache/bin
# ./apachectl start
其中需要注意,因為Aapche不支援root使用者,所以需要確認Linux檔案系統中有nobody組和nogroup組。
在/etc新增兩個使用者
vi /etc/passwd :
root::0:0:root:/:/bin/bash
nobody::65534:65533:nobody:/:/bin/bash
vi /etc/group :
body::65533:
nogroup::65534:nobody
root::0:
users::100:
正常啟動會彈出
若有其他問題goole、度娘一下,都是常見問題
6、開啟瀏覽器輸入http://ip:8080就能看見apache測試畫面啦
至此,搭建lasp環境完成...