經過幾天的努力終于在arm-linux平台上搭建了apache+sqlite+php平台.
apche與sqlite網上有不少資料,而php for arm-linux很少.為了在arm平台上安裝php發了不少時間.是以将搭建過程發表在此,希望對大家有所幫助.
Sqlite for Arm Linux安裝
1、 下載下傳sqlite3.3.8:請到http://www.sqlite.org/download.html,将下載下傳的代碼包解開,将生成sqlite3.3.8目錄
2、 修改configure檔案,将下面語句注釋掉
#if test "$cross_compiling" = "yes"; then
# { { echo "$as_me:$LINENO:: error: unable to find a compiler for building build tools" >&5#echo "$as_me: error: unable to find a compiler for building build tools" >&2;}
# { (exit 1); exit 1; }; }
#fi
. . .
#else
# test "$cross_compiling" = yes &&
# { { echo "$as_me:$LINENO:: error: cannot check for file existence when cross compiling" >&5
#echo "$as_me: error: cannot check for file existence when cross compiling" >&2;}
# { (exit 1); exit 1; }; }
. . .
#else
# test "$cross_compiling" = yes &&
# { { echo "$as_me:$LINENO:: error: cannot check for file existence when cross compiling" >&5
#echo "$as_me: error: cannot check for file existence when cross compiling" >&2;}
# { (exit 1); exit 1; }; }
3、配置
./configure –prefix=/data0/sqlite --disable-tcl --host=arm-linux
4、 修改Makefile檔案
将BCC = arm-linux-gcc -g -O2改成BCC = gcc -g -O2
5、 修改Makefile檔案,将sqlite3程式以靜态鍵接庫方式編譯
先需增加libsqlite3.a的編譯
再将sqlite3$(TEXE): $(TOP)/src/shell.c .libs/libsqlite3.la sqlite3.h
改成lite3$(TEXE): $(TOP)/src/shell.c .libs/libsqlite3.a sqlite3.h
将 -o $@ $(TOP)/src/shell.c .libs/libsqlite3.la /
改成 -o $@ $(TOP)/src/shell.c .libs/libsqlite3.a /
6、 Make
7、 #arm-linux-strip sqlite3
8、 将sqlite3上傳至終端
9、 Sqlite3程式測試
sqlite3 test
,if you see the following messages:
SQLite version 3.3.8
Enter ".help" for instructions
sqlite>
input some commands to do something,
sqlite> create table tbl(one varchar(10),two smallint);
sqlite> insert into tbl values('hello',10);
sqlite> insert into tbl values('goodbye',20);
sqlite> .quit
10、 測試C程式
make a 'test.c' file in 'build' directory, content as showed:
#include
#include "sqlite3.h"
static int callback(void *NotUsed, int argc, char **argv, char **azColName){
int i;
for(i=0; i printf("%s = %s/n", azColName[i], argv[i] ? argv[i] : "NULL");
}
printf("/n");
return 0;
}
int main(int argc, char **argv){
sqlite3 *db;
char *zErrMsg = 0;
int rc;
if( argc!=3 ){
fprintf(stderr, "Usage: %s DATABASE SQL-STATEMENT/n", argv[0]);
exit(1);
}
rc = sqlite3_open(argv[1], &db);
if( rc ){
fprintf(stderr, "Can't open database: %s/n", sqlite3_errmsg(db));
sqlite3_close(db);
exit(1);
}
rc = sqlite3_exec(db, argv[2], callback, 0, &zErrMsg);
if( rc!=SQLITE_OK ){
fprintf(stderr, "SQL error: %s/n", zErrMsg);
sqlite3_free(zErrMsg);
}
sqlite3_close(db);
return 0;
}
#arm-linux-gcc test.c -L.libs -lsqlite3 –static
#arm-linux-strip a.out
将a.out程式上傳至終端,并執行
#a.out test "select * from tbl"
one = hello
two = 10
one = goodbye
two = 20
apache伺服器for ARM Linux
1. 從http://www.apache.org/ 上下載下傳apache_1.3.39.tar.gz,然後解壓縮的一個目錄,然後轉到apache_1.3.39目錄。
2. 使用本地的gcc編譯這個版本,運作:
./ configure
make 完成後,不需要make install
3. 然後建立一個新的編譯arm版本的目錄,然後在那個目錄下解壓縮apache_1.3.39.tar.gz,轉到該目錄下的apache_1.3.39,運作:
export CC="arm-linux-gcc"
./configure --prefix=/data0/apache/ --without-execstrip --enable-module=so
然後運作make 指令,這時編譯會在apache_1.3.39/src/main/gen_test_char處失敗,因為arm版本該程式無法在本地機器運作,你需要把前面編譯的本地版本的apache_1.3.39/src/main/gen_test_char覆寫這個arm版本,然後轉到arm版本的apache_1.3.39下繼續make,随後編譯到另一個程式apache_1.3.39/src/main/gen_uri_delims也出現相同的問題,也使用本地版本覆寫掉它,繼續make,直到最後編譯成功。
4. --prefix=/data0/apache /指定了安裝的目錄為/data0/apache/,運作make install,所有編譯好的arm版本的apache程式都安裝到了/data0/apache/目錄下,你把這個目錄壓縮後,上傳至終端上,然後修改conf/httpd.conf配置檔案。
5.注意要修改conf/httpd.conf,增加ServerName www.willfar-ertu.com:80,否則在啟動服務時會報一個警告httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
6 .執行如下指令判斷apache是否安裝成功 http://IP:80 如果顯示了apache說明頁面,則說明安裝成功.如果出現403的錯誤提示,請确認apache的目錄權限是否為755,包括apache的上級目錄.
PHP for ARM Linux
1. 從http://www.php.net 上下載下傳php-4.4.8.tar.gz,然後解壓縮的一個目錄,然後轉到php-4.4.8目錄
2. export CC=”arm-linux-gcc”
3. 修改configure檔案,将其中交叉編譯錯誤處理注釋掉,例:
#if test "$cross_compiling" = yes; then
# { echo "configure: error 7: can not run test program while cross compiling" 1>&2; exit 1; }
#else
4 ./configure --prefix=/data0/php --with-apxs=/data0/apache/bin/apxs --enable-pdo=shared --with-sqlite=shared --with-pdo-sqlite=shared --with-zlib --host=arm-linux --enable-track-vars --with-xml
5. 執行./configure會報一些錯誤,根據錯誤提示,修改configure檔案注釋掉錯誤處理,直到成功
6.修改Makefile檔案,将其中
EXTRA_LIBS = -lcrypt -l -lcrypt -lz -lm -lcrypt –lcrypt
替換為
EXTRA_LIBS = -lcrypt -lcrypt -lz -lresolv -lm -ldl -lnsl -lcrypt –lcrypt
如果不替換會在最後連結時,報can not find –l -lcrypt錯誤
7.make
8.make install時會報php程式無法執行,将交叉編譯好的php備份成php_arm,再将本地編譯好的php替換掉交叉編譯的php. 繼續make install
9.執行完make install後,會在/data0目錄下生成php目錄,将php-4.4.8/sapi/cli/php_arm拷貝至/data0/php/bin目錄,再将php目錄打包,并傳至終端的/data0目錄下再解壓
10.将php-4.4.8/.libs目錄下的libphp4.so檔案傳至終端/data0/apache/libexec目錄下
11.修改/data0/apache/conf目錄下的httd.conf檔案如下幾個地方
在# LoadModule foo_module libexec/mod_foo.so下面增加如下語句
LoadModule php4_module libexec/libphp4.so
DirectoryIndex index.html index.php
#
#AddType application/x-gzip .gz .tgz
AddType application/x-httpd-php .php
12.在/data0/apache/htdoc目錄下增加index.php檔案,其内容如下:
13.如果http://ip/index.php,能看到php資訊,則說明php安裝成功
PHP Version 4.4.8
System
Linux localhost 2.4.18-rmk7-pxa1 #2 四 12月 27 12:28:52 CST 2007 armv4l
Build Date
Feb 3 2008 11:58:44
Configure Command
'./configure' '--prefix=/data0/php' '--with-apxs=/data0/apache/bin/apxs' '--enable-pdo=shared' '--with-sqlite=shared' '--with-pdo-sqlite=shared' '--with-zlib' '--host=arm-linux' '--enable-track-vars' '--with-xml'
Server API
Apache
Virtual Directory Support
disabled
Configuration File (php.ini) Path
/data0/php/lib
PHP API
20020918
PHP Extension
20020429
Zend Extension
20050606
Debug Build
no
Zend Memory Manager
enabled
Thread Safety
disabled
Registered PHP Streams
php, http, ftp, compress.zlib
php與sqlite3結合
先從php網站上下載下傳php-sqlite3壓縮包
1.把壓縮包,解壓縮到一個目錄.
2.進入該目錄,運作/data0/php/bin/phpize
3../configure --with-php-config=/data0/php/bin/php-config --with-sqlite3=你的sqlite3安裝目錄
4.make
5.make install
6.把生成的sqlite3.so放到php擴充目錄下.
7.在php.ini加載一下sqlite3.so子產品