我們使用開源的嵌入式網頁服務程序AppWeb為landog和oabox項目提供webserver服務。下面是appWeb項目的鏈接:
http://www.appwebserver.org/ :官方網站
http://www.appwebserver.org/forum/index.php :幫助論壇
我們選用最新的appweb-2.2.2版本下載地址如下:
http://www.appwebserver.org/software/appweb-src-2.2.2-5.tar.gz
在oabox項目需要php5和ssl支持,在編譯AppWeb之前先要編譯php5和matrixssl。
關於appweb的配置見下面的頁面:
/AppWebConfig :配置appweb
PHP5
由於php5需要zlib庫和libxml2庫的支持,我們首先交叉編譯zlib庫。
zlib
下載 zlib-1.2.3.tar.gz 到~/webserver/src/目錄,運行下面的命令:
$ cd ~/webserver/
$ tar xvzf src/zlib-1.2.3.tar.gz
$ cd zlib-1.2.3/
$ CC=armeb-linux-gcc ./configure --shared
$ make
$ cp -d libz.so* /Your/CrossCompile/Path/lib/ //將生成的動態庫拷貝到交叉編譯器的lib目錄
$ cp zlib.h /Your/CrossCompile/Path/include/ //將zlib的頭文件拷貝到交叉編譯器的include目錄
$ cp zconf.h /Your/CrossCompile/Path/include/
libxml2
下載 libxml2-2.6.28.tar.gz 到~/webserver/src/目錄,運行下面的命令:
$ cd ~/webserver/
$ tar xvzf src/libxml2-2.6.28.tar.gz
$ cd libxml2-2.6.28/
$ ./configure --host=armeb-linux
$ make
編譯完之后在 .libs/目錄下面生成libxml2的動態庫,將它們拷貝到交叉編譯器的lib目錄:
$ cp -d .libs/libxml2.so* /Your/CrossCompile/Path/lib/
php5
下載 php-5.2.3.tar.bz2 包到~/webserver/src/目錄,運行下面的命令:
$ cd ~/webserver/
$ tar jxvf src/php-5.2.3.tar.bz2
$ cd php-5.2.3/
$ export CC=armeb-linux-gcc
$ export AR=armeb-linux-ar
$ export CXX=armeb-linux-c++
$ export RANLIB=armeb-linux-ranlib
$ export STRIP=armeb-linux-strip
$ export LD=armeb-linux-ld
$ export NM=armeb-linux-nm
由於PHP直接交叉編譯時有問題,我們還要修改configure文件:
$ vi configure
將106003行:
{ echo "configure: error: Your system seems to lack POSIX threads." 1>&2; exit 1; }
替換為:
{ echo "configure: error: Your system seems to lack POSIX threads." 1>&2; }#exit 1; }
保存退出后執行下面的命令:
$ ./configure --prefix=/home/lvl/install/php5.0/ --host=armeb-linux --target=armeb-linux --cache-file=config.cache --disable-debug --disable-rpath --enable-bcmath --enable-calendar --enable-embed=shared --enable-maintainer-zts --enable-force-cgi-redirect --enable-ftp --enable-inline-optimization --enable-magic-quotes --enable-memory-limit --enable-pic --enable-safe-mode --enable-sockets --enable-track-vars --sysconfdir=/home/lvl/install/php5.0/etc/appWeb --enable-mbstring=cn --enable-sqlite --without-pear --without-iconv --with-zlib --disable-ipv6
由於交叉編譯器的缺陷,configure時部分檢測沒有正確執行需要修改一些內容:
修改main/php_config.h
$ vi main/php_config.h
在1810行:(也可能在其他地方)
/* #undef HAVE_STDARG_PROTOTYPES */
下面添加:
#define HAVE_STDARG_PROTOTYPES 1
修改Makefile
$ vi Makefile
將65行:
EXTRA_LIBS = -lcrypt -lcrypt -lrt -lz -lm -lxml2 -lxml2 -lxml2 -lcrypt -lxml2 -lxml2 -lxml2 -lcrypt
改為:
EXTRA_LIBS = -lcrypt -lcrypt -lrt -lz -lm -lxml2 -lxml2 -lxml2 -lcrypt -lxml2 -lxml2 -lxml2 -lcrypt -lpthread -ldl
修改完之后就可以進行編譯了:
$ make
$ makeinstall
php程序被安裝在/home/lvl/install/php5.0/目錄,其中libphp5.so在lib目錄下面。
MatrixSSL
AppWeb 支持https訪問,為了實現該功能我們需要ssl庫。AppWeb支持OpenSSL和MatrixSSL,因為MatrixSSL體積小而且易於交叉 編譯,所以我們選用MatrixSSL。首先下載 matrixssl-1-8-3-open.tar.gz 到~/webserver/src/目錄,運行下面的命令:
$ cd ~/webserver/
$ tar xvzf src/matrixssl-1-8-3-open.tar.gz
$ cd matrixssl-1-8-3-open/src/
修改Makefile:
$ vi Makefile
將:
CC = gcc
STRIP = strip
AR = ar
RANLIB = ranlib
改為:
CC = armeb-linux-gcc
STRIP = armeb-linux-strip
AR = armeb-linux-ar
RANLIB = armeb-linux-ranlib
保存退出后運行:
$ make
AppWeb
下載 appweb-src-2.2.2-5.tar.gz 到~/webserver/src/目錄,運行下面的命令:
- --enable-ranges --with-cgi=loadable --with-php5=builtin \--with-php5-libs="php5 crypt resolv z" \--with-php5-dir="/home/lvl/landog/web/php-5.2.3/" \--with-php5-libpath=/home/lvl/landog/web/php-5. ...
--enable-ranges --with-cgi=loadable --with-php5=builtin \
--with-php5-libs="php5 crypt resolv z" \
--with-php5-dir="/home/lvl/landog/web/php-5.2.3/" \
--with-php5-libpath=/home/lvl/landog/web/php-5.2.3/libs/ \
--with-php5-iflags="-I/home/lvl/landog/web/php-5.2.3 \
-I/home/lvl/landog/web/php-5.2.3/main \
-I/home/lvl/landog/web/php-5.2.3/Zend \
-I/home/lvl/landog/web/php-5.2.3/TSRM"
為了正確編譯還需修改部分文件:
$ vi appweb/Makefile
修改77行:
LIBPATH += $(BLD_TOP)/$(BLD_PHP5_DIR)
為:
LIBPATH += $(BLD_PHP5_DIR)/libs/保存退出后運行:
$ make
Eaccelerator編譯eaccelerator
$ makeinstalleaccelerator是用來加速PHP運行的程序,一般情況是通過動態模塊的形式進行加載的。但是在交叉編譯的模塊不能正常加載,我們需要將eaccelerator編譯進libphp.so里面。
首先下載 eaccelerator-0.9.5.1.tar.bz2 到~/webserver/src/目錄,運行下面的命令將eaccelerator解壓到php-src/ext目錄下面:
$ cd ~/webserver/
$ tar jxvf src/eaccelerator-0.9.5.1.tar.bz2
$ mv eaccelerator-0.9.5.1/ eaccelerator
$ mv eaccelerator/ php-5.2.3/ext/解壓出來的eaccelerator目錄中沒有configure文件,我們需要用上面安裝到/home/lvl/install/php5.0/bin/里面的phpize來生成configure文件:
$ cd php-5.2.3/ext/eaccelerator/
$ /home/lvl/install/php5.0/bin/phpize //用你自己編譯安裝的phpize文件我們需要重新生成php5的configure文件,使之包含eaccelerator選項:
$ cd ~/webserver/php-5.2.3/
$ rm configure
$ ./buildconf --force //系統中必須有autoconf-2.13以上版本在配置選項中加入--enable-eaccelerator和--with-eaccelerator-shared-memory重新運行configure:
$ export BLD_AR_FOR_HOST=armeb-linux-ar
$ export BLD_CC_FOR_HOST=armeb-linux-gcc
$ export BLD_LD_FOR_HOST=armeb-linux-ld
$ export BLD_STRIP_FOR_HOST=armeb-linux-strip
$ export BLD_AR_FOR_BUILD=ar
$ export BLD_CC_FOR_BUILD=/usr/bin/cc
$ export BLD_LD_FOR_BUILD=/usr/bin/ld
$ export BLD_STRIP_FOR_BUILD=/usr/bin/strip
$ ./configure --prefix=/home/lvl/install/php5.0/ --host=armeb-linux --target=armeb-linux --cache-file=config.cache --disable-debug --disable-rpath --enable-bcmath --enable-calendar --enable-embed=shared --enable-maintainer-zts --enable-force-cgi-redirect --enable-ftp --enable-inline-optimization --enable-magic-quotes --enable-memory-limit --enable-pic --enable-safe-mode --enable-sockets --enable-track-vars --sysconfdir=/home/lvl/install/php5.0/etc/appWeb --enable-mbstring=cn --enable-sqlite --without-pear --without-iconv --with-zlib --disable-ipv6 --enable-eaccelerator --with-eaccelerator-shared-memory配置之前還需按上面的方法修改configure文件,運行configure之后還要修改Makefile和main/php_config.h文件。另外,還要修改ext/eaccelerator/mm.c 文件:
$ vi ext/eaccelerator/mm.c
在第30行插入:
#define MM_SEM_IPC 1
#define MM_SHM_IPC 1保存退出后運行:
$ make
運 行完之后在libs目錄下面生成libphp5.so文件。由於我們的appweb配置時采用了:--with-php5=builtin(用-- with-php5=loadable時找不到模塊!)所以編譯完libphp5.so后還需重新編譯一遍appweb。
配置eaccelerator重新編譯appweb並make install后appweb會安裝在編譯appweb時指定的"--prefix"目錄下(如:/mnt/appWeb/)。我們需要修改該目錄下的php.ini來使eaccelerator生效:
$ cd /mnt/appWeb
$ sudovi php.ini (需要根用戶權限)
在該文件末尾加入如下內容:
eaccelerator.shm_size="16"
eaccelerator.cache_dir="/tmp/eaccelerator"
eaccelerator.enable="1"
eaccelerator.optimizer="1"
eaccelerator.check_mtime="0"
eaccelerator.debug="0"
eaccelerator.filter=""
eaccelerator.shm_max="0"
eaccelerator.shm_ttl="300"
eaccelerator.shm_prune_period="300"
eaccelerator.shm_only="0"
eaccelerator.compress="1"
eaccelerator.compress_level="9"將主機上的/mnt/appWeb/目錄拷貝到開發板上的/mnt/目錄下(拷貝之前先用armeb-linux-strip工具去除appweb程序以及lib/modules/目錄動態庫中的調試信息和符號信息)。
創建eaccelerator目錄在開發板的啟動腳本里加入:
mkdir /tmp/eaccelerator
chmod 0777 /tmp/eaccelerator該目錄作為保存緩存數據的目錄。
確認eaccelerator運行在正常情況下檢驗eaccelerator是否工作的方法是用瀏覽器打開含有以下代碼的php頁面:
如果eaccelerator正常運行的話在phpinfo頁面會顯示:
Zend Engine v2.1.0 Copyright (c) 1998-2006 Zend Technologies
with eAccelerator v0.9.5-beta2 Copyright (c) 2004-2006 eAccelerator by eAccelerator