linux 搭建webserver-BOA

一、下载源码

官网地址:Boa Webserver

linux 搭建webserver-BOA_第1张图片

linux 搭建webserver-BOA_第2张图片

二、编译boa

下载得到boa-0.94.13.tar.gz,解压后进入boa-0.94.13/src目录,执行如下命令生成Makefile文件:

./configure

如果是交叉编译,需要修改 Makefile, 设置对应的交叉编译器 。例如使用arm-linux-gnueabihf工具链要找到 CC 和 CPP 变量 ,修改为:

CC = arm-linux-gnueabihf-gcc

CPP = arm-linux-gnueabihf-gcc -E

执行make编译,可能会出现一些报错,如果某些程序未安装的话:

linux 搭建webserver-BOA_第3张图片

提示 yacc: Command not found 是因为yacc未安装,需要安装yacc,通过

sudo apt-get install byacc 

命令进行安装

linux 搭建webserver-BOA_第4张图片

继续make,提示lex: Command not found,需要通过

sudo apt-get install flex 

安装lex

linux 搭建webserver-BOA_第5张图片

linux 搭建webserver-BOA_第6张图片

安装了lex,继续编译,会出现报错

linux 搭建webserver-BOA_第7张图片

需要将把compat.h 文件里的:

#define TIMEZONE_OFFSET(foo) foo##->tm_gmtoff

修改为

#define TIMEZONE_OFFSET(foo) foo->tm_gmtoff

linux 搭建webserver-BOA_第8张图片

修改后继续make,就可以正常编译通过了

linux 搭建webserver-BOA_第9张图片

三、配置boa服务

在/etc目录下创建boa目录

(如果是交叉编译的,要在目标环境运行,记得将把Ubuntu 的/etc 目录下的 mime.types 文件传到开发板的/etc目录下,如果目标环境下没有的话。mime.types 文件 是MIME(多用途因特网邮件扩展),这是web服务器支持的规范。),用于存放boa的配置文件及log文件。

linux 搭建webserver-BOA_第10张图片

在开发板根目录下建立 www 文件夹 ,www 目录下面建立文件夹 cgi-bin 目录 (用于存放后期页面及交互代码):

mkdir -p /www/cgi-bin

linux 搭建webserver-BOA_第11张图片

把boa-0.94.13目录下的boa.conf 文件传到开发板的/etc/boa目录下(如果是要在目标板上运行boa server)。

scp boa.conf [email protected]:/etc/boa

linux 搭建webserver-BOA_第12张图片

把boa 可执行程序传到开发板的 bin 目录下 。

scp boa [email protected]:/bin

linux 搭建webserver-BOA_第13张图片

在开发板/etc目录下创建group文件:

cd /etc

touch group

在开发板上使用vi编辑器打开/etc/boa目录下的boa.conf文件,需要做如下修改:

① 把里面的Group nogroup 改为Group 0 。

②把ErrorLog 和 AccessLog 这两行, 指定 log 文件的路径,把log保存到/etc/boa目录下,修改如下:

ErrorLog /etc/boa/error_log

# Please NOTE: Sending the logs to a pipe ('|'), as shown below,

# is somewhat experimental and might fail under heavy load.

# "Usual libc implementations of printf will stall the whole

# process if the receiving end of a pipe stops reading."

#ErrorLog "|/usr/sbin/cronolog --symlink=/var/log/boa/error_log /var/log/boa/error-%Y%m%d.log"

# AccessLog: The location of the access log file. If this does not

# start with /, it is considered relative to the server root.

# Comment out or set to /dev/null (less effective) to disable

# Access logging.

AccessLog /etc/boa/access_log

③ 把#ServerName www.your.org.here这一行, 修改为ServerName www.your.org.here:

​
# ServerName: the name of this server that should be sent back to

# clients if different than that returned by gethostname + gethostbyname

ServerName www.your.org.here

​

④ 然后找到DocumentRoot /var/www这一行, 修改为DocumentRoot /www:

DocumentRoot /www

⑤ 然后找到ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/这一行, 修改为ScriptAlias /cgi-bin/ /www/cgi-bin/:

ScriptAlias /cgi-bin/ /www/cgi-bin/

上面就是boa.conf配置文件需要修改的几点内容。

最后,进入我们前面创建的 www 目录, 然后使用 vi index.html 命令建立 index.html 网页文件进行测试,关于简单网页的设计大家可以上网搜一些教程。这里我们设计一个简单的网页如:


 
  
  boa服务器测试
  
 
 
  

boa test

smallerxuan

linux boa test test test。

保存并退出 index.html。到了这一步我们的web服务器就大致搭建完成了,服务器上有一个简单的网页文件index.html。

四、测试boa服务

下面进行简单的测试:

在我们的开发板上输入boa 命令启动 web 服务器,启动的时候可能会因为日志文件不存而报错,只需要创建响应的文件即可 。

linux 搭建webserver-BOA_第14张图片

输入 如下命令查看boa程序是否启动成功:

ps -e | grep boa

linux 搭建webserver-BOA_第15张图片

boa 进程启动成功后,在浏览器中输入我们开发板的 IP 地址就可以访问到 index.html 网页:

linux 搭建webserver-BOA_第16张图片

可见,我们可以通过浏览器访问我们使用开发板搭建的web服务器上的网页,表明我们已经成功在开发板搭建了基于boa的web服务器。

本文只是简单地演示打通开发板web服务器环境并设计了一个简单地网页,后续我们再继续来探究如何通过网页来与我们地开发板进行交互,如:通过网页点亮开发板上地led、把开发板上地一些数据传到网页上进行显示等内容

 

你可能感兴趣的:(嵌入式,学习日记,linux,嵌入式webserver,BOA)