apache+sqlite+php for Arm Linux

經過幾天的努力終於在arm-linux平臺上搭建了apache+sqlite+php平臺.
apche與sqlite網上有不少資料,而php for arm-linux很少.爲了在arm平臺上安裝php發了不少時間.所以將搭建過程發表在此,希望對大家有所幫助.
Sqlite for Arm Linux安裝
1、 下載sqlite3.3.8:請到[url]http://www.sqlite.org/download.html[/url],將下載的代碼包解開,將生成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 <stdio.h>
#include "sqlite3.h" /* orignal is <sqlite3.h> */

static int callback(void *NotUsed, int argc, char **argv, char **azColName){
int i;
for(i=0; i<argc; 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
 
 
1. [url]http://www.apache.org/[/url] 上下載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 [url]www.willfar-ertu.com:80[/url],否則在啓動服務時會報一個警告httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
6 .執行如下命令判斷apache是否安裝成功 [url]http://IP:80[/url] 如果顯示了apache說明頁面,則說明安裝成功.如果出現403的錯誤提示,請確認apache的目錄權限是否爲755,包括apache的上級目錄.
 
PHP for ARM Linux
1.     [url]http://www.php.net[/url] 上下載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
替換爲
如果不替換會在最後鏈接時,報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
 
<IfModule mod_dir.c>
    DirectoryIndex index.html index.php
</IfModule>
#
 
#AddType application/x-gzip .gz .tgz
 AddType application/x-httpd-php .php
 
12.在/data0/apache/htdoc目錄下增加index.php文件,其內容如下: <? phpinfo();?>
13.如果[url]http://ip/index.php[/url],能看到php信息,則說明php安裝成功 
 
 

PHP Version 4.4.8


SystemLinux localhost 2.4.18-rmk7-pxa1 #2 四 12月 27 12:28:52 CST 2007 armv4l
Build DateFeb 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 APIApache
Virtual Directory Supportdisabled
Configuration File (php.ini) Path/data0/php/lib
PHP API20020918
PHP Extension20020429
Zend Extension20050606
Debug Buildno
Zend Memory Managerenabled
Thread Safetydisabled
Registered PHP Streamsphp, 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模塊
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章