当前位置: 首页 > 工具软件 > lighttpd-cpp > 使用案例 >

(OK) port_lighttpd_to_Android——没有基于android 4.4源码

劳法
2023-12-01
[root@localhost lighttpd-1.4.37]# pwd
/opt/cBPM-android/lighttpd-1.4.37

[root@localhost lighttpd-1.4.37]# ls /opt/cBPM-android/criteria-lin/lib/libpcre.a
/opt/cBPM-android/criteria-lin/lib/libpcre.a            //下面有libpcre.a的编译过程

[root@localhost pcre-8.37]# pwd
/opt/cBPM-android/pcre-8.37
[root@localhost pcre-8.37]# cp pcre.h /opt/cBPM-android/lighttpd-1.4.37/src/

[root@localhost lighttpd-1.4.37]# gedit src/network.c
添加:
#include "sys/un.h>

--------------------------------------问题: sock_addr has no member named un ,解决方法如下:
[root@localhost lighttpd-1.4.37]# gedit config.h
添加:
#define HAVE_SYS_UN_H 1
[root@localhost lighttpd-1.4.37]# make -j5
--------------------------------------
[root@localhost lighttpd-1.4.37]# gedit src/plugin.c
注释掉:
//#include "plugin-static.h"
--------------------------------------

+++++++++++++++++++++++++++++++++++++++++编译 lighttpd-1.4.37,将用到的库静态链接进来
[root@localhost lighttpd-1.4.37]# pwd
/opt/cBPM-android/lighttpd-1.4.37
[root@localhost lighttpd-1.4.37]#

export NDK_ROOT="/opt/android-on-linux/android-ndk-r8e"
export SYSROOT="$NDK_ROOT/platforms/android-14/arch-arm"
export CFLAGS="-g --sysroot=$SYSROOT --pipe -I$NDK_ROOT/sources/cxx-stl/stlport/stlport -I$NDK_ROOT/platforms/android-14/arch-arm/usr/include -I$NDK_ROOT/toolchains/arm-linux-androideabi-4.7/prebuilt/linux-x86_64/include -I$NDK_ROOT/toolchains/arm-linux-androideabi-4.7/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.7/include-fixed -I$NDK_ROOT/toolchains/arm-linux-androideabi-4.7/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.7/include"
export CPPFLAGS="$CFLAGS"
export CXXFLAGS="$CFLAGS"
export LDFLAGS="-L$NDK_ROOT/sources/cxx-stl/stlport/libs/armeabi-v7a -L/opt/cBPM-android/criteria-lin/lib -L/opt/cBPM-android/lighttpd-1.4.37/src/.libs -lstlport_static -lgcc -lc"
export CPATH="$NDK_ROOT/toolchains/arm-linux-androideabi-4.7/prebuilt/linux-x86_64/bin"
export CPP="$CPATH/arm-linux-androideabi-cpp"
export CXX="$CPATH/arm-linux-androideabi-g++"
export CC="$CPATH/arm-linux-androideabi-gcc"
export LD="$CPATH/arm-linux-androideabi-ld"
export AR="$CPATH/arm-linux-androideabi-ar"

./configure --host="arm-linux-androideabi" --without-bzip2 --without-zlib

--------------------------------------
./configure --host="arm-linux-eabi" --enable-static --disable-shared --without-bzip2 --without-zlib
--------------------------------------
export LDFLAGS="-L$NDK_ROOT/sources/cxx-stl/stlport/libs/armeabi-v7a -L/opt/cBPM-android/criteria-lin/lib -static -lstlport_static -lgcc -lc"
export CFLAGS="-DLIGHTTPD_STATIC -g --sysroot=$SYSROOT --pipe -I$NDK_ROOT/sources/cxx-stl/stlport/stlport -I$NDK_ROOT/platforms/android-14/arch-arm/usr/include -I$NDK_ROOT/toolchains/arm-linux-androideabi-4.7/prebuilt/linux-x86_64/include -I$NDK_ROOT/toolchains/arm-linux-androideabi-4.7/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.7/include-fixed -I$NDK_ROOT/toolchains/arm-linux-androideabi-4.7/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.7/include"
--------------------------------------
[root@localhost lighttpd-1.4.37]# gedit config.h
添加:
#define HAVE_SYS_UN_H 1
[root@localhost lighttpd-1.4.37]# make -j5
--------------------------------------

[root@localhost lighttpd-1.4.37]# ll src/lighttpd
-rwxr-xr-x. 1 root root 926240 10月 20 17:02 src/lighttpd
[root@localhost lighttpd-1.4.37]#

编译完后会产生lighttpd
[root@localhost lighttpd-1.4.37]# adb push src/lighttpd /data/data/webserver

把 plugins (mod_*.so)都放到/data/data/webserver/plugin
[root@localhost lighttpd-1.4.37]# adb push src/.libs/somod /data/data/webserver/plugin
[root@localhost lighttpd-1.4.37]# adb push src/.libs/mod /data/data/webserver/plugin

[root@localhost lighttpd-1.4.37]# mv src/.libs/mod*.so src/.libs/somod
[root@localhost lighttpd-1.4.37]# ls src/.libs/        库位置

另外 libpcre.so 是需要的,请确定libpcre.so有存在。本文

------------------------------------------------
[root@localhost lighttpd-1.4.37]# ls /opt/cBPM-android/criteria-lin/lib/
Criteria.xml   helloworldcpp  libiconv.a         libLibraries.a   libsqlite.so    libWorkflowEngineD.so  
libc.so        libiconv.so.2      libLibraries.so  libstdc++.so          libxerces-c-3.1.so
executer       libdl.a        libiconv.so.2.5.1  libpcre.a        libstlport.so         libxerces-c.a
helloworld     libdl.so       libiconv.so.bac    libsqlite.a      libWorkflowEngineD.a  temp2.txt
[root@localhost lighttpd-1.4.37]#
------------------------------------------------

+++++++++++++++++++++++++++++++++++++++
[root@localhost ~]# adb root
[root@localhost ~]# adb shell
root@mb526:/ # mkdir /data/data/webserver
root@mb526:/ # mkdir /data/data/webserver/plugin
root@mb526:/ # mkdir /data/data/www
root@mb526:/ # mkdir /data/data/www/log
root@mb526:/ # mkdir /data/data/www/run
root@mb526:/ # mkdir /data/data/www/etc
root@mb526:/ # mkdir /data/data/www/etc/lighttpd
root@mb526:/ # mkdir /data/data/www/etc/lighttpd/conf.d
root@mb526:/ # mkdir /data/data/www/tmp
root@mb526:/ # mkdir /data/data/www/htdocs
root@mb526:/ # mkdir /data/data/www/cgi-bin
root@mb526:/ # chmod 755 /data/data/www/cgi-bin

root@mb526:/ #

[root@localhost lighttpd-1.4.37]# pwd
/opt/cBPM-android/lighttpd-1.4.37
[root@localhost lighttpd-1.4.37]# adb push src/lighttpd /data/data/webserver
[root@localhost lighttpd-1.4.37]# adb push doc/config/conf.d/ /data/data/www/etc/lighttpd/conf.d/

[root@localhost lighttpd-1.4.37]# mkdir src/.libs/mod
[root@localhost lighttpd-1.4.37]# mv src/.libs/lib*.a src/.libs/mod/
[root@localhost lighttpd-1.4.37]# adb push src/.libs/mod/ /data/data/webserver/plugin/

接下来把 lighttpd soruce 内的 doc/config/conf.d 内的所有档案通通放到 /data/data/www/etc/lighttpd/conf.d/
然后在/data/data/www/etc/lighttpd/ 放上 lighttpd.conf, 内容如下:

[root@localhost lighttpd-1.4.37]# gedit doc/config/lighttpd.conf

#######################################################################
## /etc/lighttpd/lighttpd.conf
##
## check /etc/lighttpd/conf.d/*.conf for the configuration of modules.
#######################################################################

#######################################################################
## Some Variable definition which will make chrooting easier.
##
## if you add a variable here. Add the corresponding variable in the
## chroot example aswell.
##
var.log_root    = "/data/data/www/log"
var.server_root = "/data/data/www"
var.state_dir   = "/data/data/www/run"
var.home_dir    = "/data/data/www"
var.conf_dir    = "/data/data/www/etc/lighttpd"

var.cache_dir   = home_dir + "/tmp"
var.socket_dir  = home_dir + "/tmp"

server.modules = (
  "mod_access",
)

server.port = 8000
server.use-ipv6 = "disable"

#server.username  = "lighttpd"
#server.groupname = "lighttpd"

server.core-files = "enable"

server.document-root = server_root + "/htdocs"
#server.pid-file = state_dir + "/lighttpd.pid"

server.errorlog             = log_root + "/error.log"

server.event-handler = "linux-sysepoll"

# not supported?
# I got an error "server.network-backend has a unknown value: linux-sendfile"
#server.network-backend = "linux-sendfile"

server.max-fds = 512

server.stat-cache-engine = "simple"
server.max-connections = 170

index-file.names += (
  "index.xhtml", "index.html", "index.htm", "default.htm", "index.php"
)

url.access-deny = ( "~", ".inc" )
$HTTP["url"] =~ "\.pdf$" {
  server.range-requests = "disable"
}

##
## mimetype mapping
##
include "conf.d/mime.conf"

server.follow-symlink = "enable"

server.upload-dirs = ( "/data/data/www/tmp" )

#include "conf.d/webdav.conf"

#--------------------------------------------

[root@localhost lighttpd-1.4.37]# adb push doc/config/lighttpd.conf /data/data/www/etc/lighttpd/

上述动作都准备完毕后, 就可以用下述的指令来测试看看整个环境设定是否ok了
### $ ./lighttpd -t -f /data/data/www/etc/lighttpd/lighttpd.conf -m /system/lib/web-plugin        //这行不用

root@mb526:/data/data/webserver # ./lighttpd -t -f /data/data/www/etc/lighttpd/lighttpd.conf
Syntax OK
root@mb526:/data/data/webserver #

如果没问题的话会, 执行结果会显示
Syntax OK

再来就是验证是否web server可以运行了, 用以下指令来启动lighttpd,    -m 指明lib的位置
root@mb526:/data/data/webserver # ./lighttpd -D -f /data/data/www/etc/lighttpd/lighttpd.conf -m /data/data/webserver/plugin

在/data/data/www/htdocs 内放一个index.html来测试
-------------------

   
       

Hello, lighthttpd on Android!!


   

-------------------

[root@localhost lighttpd-1.4.37]# adb push index.html /data/data/www/htdocs

在 宿主机(笔记本)的浏览器访问: http://192.168.0.101:8000/
输出结果:
------------------------
Hello, lighthttpd on Android!!
------------------------

至此,移植成功。

++++++++++++++++++++++++++++++++++++++++++++++++++


以下是要说明怎么启动cgi (也许google可以找到很多答案, 但是这边是我动手try过后确定可行的方法)

[root@localhost lighttpd-1.4.37]# gedit doc/config/lighttpd.conf

edit lighttpd.conf to add mod_alias plugin. 这个动作是一定要作的, 不然会发现就算之后已经有load mod_cgi, 且对应的conf 都设定了, 但却还是不 work.
-------------------
server.modules = (
"mod_access",
"mod_alias"
)
.....
.....
include "conf.d/cgi.conf"
-------------------

[root@localhost lighttpd-1.4.37]# adb push doc/config/lighttpd.conf /data/data/www/etc/lighttpd/

[root@localhost lighttpd-1.4.37]# gedit doc/config/conf.d/cgi.conf

再来就是去编辑 cgi.conf, 取消注释
-------------------
alias.url += ( "/cgi-bin" => server_root + "/cgi-bin" )
$HTTP["url"] =~ "^/cgi-bin" {
   cgi.assign = ( "" => "" )
}
-------------------

[root@localhost lighttpd-1.4.37]# adb push doc/config/conf.d/cgi.conf /data/data/www/etc/lighttpd/conf.d/

[root@localhost lighttpd-1.4.37]# gedit hello.c

示范用C 写一个简单的cgi 程序来测试, 很简单, 试试以下内容:
-------------------
#include
int main(void) {
    printf("Content-Type: text/html\n\n");
    printf("Hello world\n\n");
    return 0;
}
-------------------
》》》》》》》》》》》(OK) 宿主机交叉编译hello.c  for  android (--sysroot),不使用Android.mk和ndk-build

export PATH=$PATH:/opt/android-on-linux/android-ndk-r8e/toolchains/arm-linux-androideabi-4.7/prebuilt/linux-x86_64/bin/

[root@localhost lighttpd-1.4.37]# arm-linux-androideabi-gcc --sysroot=/opt/android-on-linux/android-ndk-r8e/platforms/android-14/arch-arm/ hello.c -o hello

[root@localhost lighttpd-1.4.37]# adb push hello /data/data/www/cgi-bin

将其编译好后放到/data/data/www/cgi-bin , 比如说 first, 之后就透过browser来测试看看
http://localhost:4080/cgi-bin/hello

如果成功的话, 可以看到browser上 Hello world!

------------------------至此,CGI成功

root@mb526:/data/data/webserver # ./lighttpd -D -f /data/data/www/etc/lighttpd/lighttpd.conf -m /data/data/webserver/plugin
------------------------




+++++++++++++++++++++++++++++++ 编译 pcre-8.37 静态库
[root@localhost pcre-8.37]#
/opt/cBPM-android/pcre-8.37
[root@localhost pcre-8.37]#

export NDK_ROOT="/opt/android-on-linux/android-ndk-r8e"
export SYSROOT="$NDK_ROOT/platforms/android-14/arch-arm"
export CFLAGS="-g --sysroot=$SYSROOT --pipe -I$NDK_ROOT/sources/cxx-stl/stlport/stlport -I$NDK_ROOT/platforms/android-14/arch-arm/usr/include -I$NDK_ROOT/toolchains/arm-linux-androideabi-4.7/prebuilt/linux-x86_64/include -I$NDK_ROOT/toolchains/arm-linux-androideabi-4.7/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.7/include-fixed -I$NDK_ROOT/toolchains/arm-linux-androideabi-4.7/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.7/include"
export CPPFLAGS="$CFLAGS"
export CXXFLAGS="$CFLAGS"
export LDFLAGS="-L$NDK_ROOT/sources/cxx-stl/stlport/libs/armeabi-v7a -L/opt/cBPM-android/criteria-lin/lib -static -lstlport_static -lgcc -lc"
export CPATH="$NDK_ROOT/toolchains/arm-linux-androideabi-4.7/prebuilt/linux-x86_64/bin"
export CPP="$CPATH/arm-linux-androideabi-cpp"
export CXX="$CPATH/arm-linux-androideabi-g++"
export CC="$CPATH/arm-linux-androideabi-gcc"
export LD="$CPATH/arm-linux-androideabi-ld"
export AR="$CPATH/arm-linux-androideabi-ar"

./configure --host="arm-linux-eabi"  --enable-static --disable-shared

make -j5

[root@localhost pcre-8.37]# ls .libs/libpcre.a
[root@localhost pcre-8.37]# cp .libs/libpcre.a /opt/cBPM-android/criteria-lin/lib

++++++++++++++杂项
$ ldd ./libtest.so

 类似资料: