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

Hi3520D 上移植 lighttpd

曾航
2023-12-01

编译环境:
虚拟机环境:CentOS 6.8 64bit
交叉编译器:arm-hisiv200-linux-gcc

1, 下载
(1)到官网上下载 lighttpd 源码包
http://www.lighttpd.net/download/
这里下载的是 lighttpd-1.4.32.tar.gz 版本,(lighttpd-1.4.45.tar.gz版本需要 pcre 库的支持)

2,编译与安装
(1)将 lighttpd-1.4.32.tar.gz 放到 /opt/work/modules/lighttpd/ 目录下,解压缩。
(2)进入文件夹 lighttpd-1.4.32,创建shell脚本 config_arm_hisiv200.sh
(3)config_arm_hisiv200.sh 写入内容
#! /bin/sh
./configure –prefix=/mnt/sdcard/web –host=arm-hisiv200-linux –disable-FEATURE –disable-lfs –disable-ipv6 –without-PACKAGE –without-openssl –without-kerberos5 –without-pcre –without-zlib –without-bzip2 –without-lua “CC=arm-hisiv200-linux-gcc -EL” “CFLAGS=-EL” “LDFLAGS=-EL”
(4)设置权限
chmod 777 config_arm_hisiv200.sh
(5)运行
./config_arm_hisiv200.sh
配置后结果:
Plugins:

enabled:
mod_access
mod_accesslog
mod_alias
mod_auth
mod_authn_file
mod_cgi
mod_compress
mod_deflate
mod_dirlisting
mod_evhost
mod_expire
mod_extforward
mod_fastcgi
mod_flv_streaming
mod_indexfile
mod_proxy
mod_rrdtool
mod_scgi
mod_secdownload
mod_setenv
mod_simple_vhost
mod_ssi
mod_staticfile
mod_status
mod_userdir
mod_usertrack
mod_webdav
disabled:
mod_authn_gssapi
mod_authn_ldap
mod_authn_mysql
mod_cml
mod_geoip
mod_magnet
mod_mysql_vhost
mod_redirect
mod_rewrite

Features:

enabled:
auth-crypt
disabled:
compress-bzip2
compress-deflate
compress-gzip
large-files
network-ipv6
network-openssl
regex-conditionals
stat-cache-fam
storage-gdbm
storage-memcached
webdav-locks
webdav-properties

(6)编译
make && make install

(7)安装完后,在 /mnt/sdcard/web 目录生产3个目录
lib/ sbin/ share/

3,配置 lighttpd
(1)在安装目录 /mnt/sdcard/web 中手动创建如下文件夹:cache、cgi-bin、config、log、sockets、upload、vhosts、webpages
(2)将源码包中doc/config目录下的config.d、lighttpd.conf和modules.conf复制到安装目录中config文件夹里面;
(3)修改 lighttpd.conf 文件
将16行至20行修改为如下所示:

var.log_root    = "/home/pub/johnny/network/install/log"  
var.server_root = "/home/pub/johnny/network/install"  
var.state_dir   = "/home/pub/johnny/network/install"  
var.home_dir    = "/home/pub/johnny/network/install"  
var.conf_dir    = "/home/pub/johnny/network/install/config"  

将61行和93行修改

var.cache_dir = server_root + “/cache”
server.use-ipv6 = “disable”

将104和105行注释掉,如下所示::

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

将115行修改为如下所示:

server.document-root = server_root + "/webpages"  

将127行注释掉,如下所示:

#server.pid-file = state_dir + "/lighttpd.pid" 

如果不需要查看错误日志文件,可以将141行注释掉,如下所示:

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

将152行、158行、191行注释掉,如下所示:

#include "conf.d/access_log.conf"  
#include "conf.d/debug.conf"  
#server.network-backend = "linux-sendfile"  

根据系统资源设置207行和225行的数值,本系统的设置分别如下

server.max-fds = 256
server.max-connections = 128

将314至316行注释掉,如下所示:

#$HTTP["url"] =~ "\.pdf$" {  
#  server.range-requests = "disable"  
#}****

将373行修改为如下所示:
server.upload-dirs = ( “/mnt/sdcard/web/upload” )

(4) 修改 modules.conf文件

找到44行,将注释符去掉,如下所示:
“mod_alias”,

使能fastcgi模块,去掉132行的注释,使能fastcgi:
include “conf.d/fastcgi.conf”

在conf.d文件夹里面的fastcgi.conf里面添加:
*#添加允许执行的FastCGI扩展名*
fastcgi.map-extensions = ( “.php”,”.pl”,”.fcgi”,”.fastcgi” => “.fastcgi”)

fastcgi.debug = 65535
fastcgi.server = (
“.cgi” => (
“base.fastcgi.handler”=>(
“socket” => “/tmp/lighttpd.socket”,
“check-local” => “disable”,
“bin-path” => “/mnt/sdcard/web/5400fcgi”,
“min-procs” => 1,
“max-procs” => 1,
“idle-timeout” => 30
)
)
)

写一个测试程序:
[cpp] view plain copy

include

int main(void)
{
char *requestMethod=NULL;
struct in_addr stInAddr;
char *contentLength=NULL;
char *scriptName=NULL;

while( FCGI_Accept() >= 0)
{  
    printf( "Content-Type:application/json;charset=UTF-8\r\n" );
    printf( "Content-Length: 27\r\n" );
    printf("\r\n");
    printf( "{\"result\":1,\"employeeno\":1}" );
}  

}

编译出可执行文件5400fcgi;

在PC上运行http://202.202.202.222/test.cgi,在开发板上打印出printf结果;

(5) 进入开发板,启动lighttpd服务器:
./lighttpd -f ../config/lighttpd.conf

 类似资料: