apache+sqlite+php for Arm Linux)

來源:互聯網
上載者:User
文章目錄
  • PHP Version 4.4.8
  •                                                                               php與sqlite3結合

經過幾天的努力終於在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 <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

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

<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.如果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模組

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.