废话不罗嗦,直接上步骤,下面的步骤都是参考网络上的很多文章解决的,参考链接在文章最底部。
一、环境:
1.上位机:虚拟机Ubuntu-12.04
2.下位机:ARM S5PC100 Linux操作系统 jffs2文件系统
3.交叉编译工具前缀:arm-cortex_a8-linux-gnueabi-
4.上位机的工作目录:/root/Software (boa就解压在这个目录下)
5.下位机的根文件系统在上位机中的路径:/root/nfs/rootfs/
二、下载boa
Boa官网:[http://www.boa.org](http://www.boa.org).
或者点击下面的第一个here,下载<span>boa-0.94.13.tar.gz</span>
二、安装、编译boa
1.在上位机中解压<span>boa-0.94.13.tar.gz</span>
<span> tar -xf <span>boa-0.94.13.tar.gz</span></span>
<span> 在当前目录产生了boa-0.94.13目录</span>
<span>
<span>2.生成Makefile</span>
<span> cd boa-0.94.13/src</span>
<span style="line-height:1.5;"> ./configure</span>
<span style="line-height:1.5;"> 此时在src目录生成了一个Makefile文件
<span style="line-height:1.5;">
<span style="line-height:1.5;">3.获得交叉编译工具的名称</span>
<span style="line-height:1.5;"> 在上位机命令行中输入arm-然后按两下tab,如果能够自动补全,那么就复制这个前缀,若不能自动补全,那么最好先安装交叉编译工具。现在假设你的交叉编译工具与我的相同(见第一节环境部分)。
<span style="line-height:1.5;">
<span style="line-height:1.5;">4.安装boa</span>
<span style="line-height:1.5;"> vi Makefile
<span style="line-height:1.5;">
<span style="line-height:1.5;"> 将CC=gcc和CPP=gcc -E修改为:
<span style="line-height:1.5;"> <span style="font-family:Arial;font-size:14px;line-height:26px;background-color:#FFFFFF;">CC = <span>arm-cortex_a8-linux-gnueabi-</span></span><span style="font-family:Arial;font-size:14px;line-height:26px;background-color:#FFFFFF;">gcc</span>
CPP = arm-cortex_a8-linux-gnueabi-gcc -E
<span style="line-height:1.5;">
<span style="line-height:1.5;"> make (如果执行make出错,请看文章最后的附录)</span>
<span style="line-height:1.5;"> 编译成功后,</span><span style="line-height:1.5;">当前目录会生成boa可执行文件,先减小文件体积</span>
<span style="line-height:1.5;"> <span style="font-family:Arial;font-size:14px;line-height:26px;background-color:#FFFFFF;">arm-cortex_a8-linux-gnueabi-strip boa</span>
<span style="line-height:1.5;"><span style="font-family:Arial;font-size:14px;line-height:26px;background-color:#FFFFFF;"> 再将其拷贝到<span style="color:#E53333;">**下位机**</span>的根文件系统中:
<span style="line-height:1.5;"> cp ./boa /root/nfs/rootfs/bin/
<span style="line-height:1.5;">
<span style="line-height:1.5;">5.配置boa</span>
<span style="line-height:1.5;"> 1.拷贝配置文件到**<span style="color:#E53333;">下位机</span>**根文件系统中:
<span style="line-height:1.5;"> mkdir /root/nfs/rootfs/etc/boa/
<span style="line-height:1.5;"> cp ../boa.conf /root/nfs/rootfs/etc/boa/ (注意,../boa.conf是相对于上面提到的src目录)
<span style="line-height:1.5;"> cd /root/nfs/rootfs/etc/boa (切换工作目录为下位机的根文件系统中)
<span style="line-height:1.5;"> vi boa.conf
<span style="line-height:1.5;"> 按照下面作相应的修改:
<span style="line-height:1.5;"> <span style="font-family:Arial;font-size:14px;line-height:26px;background-color:#FFFFFF;">User 0</span>
Group 0
#DirectoryMaker /usr/lib/boa/boa_indexer (这句原先没有被注释,现在手动加上注释)
CGIPath /bin:/usr/bin:/var/www/cgi-bin
ScriptAlias /cgi-bin/ /var/www/cgi-bin/
我们把使用boa服务器的用户和用户组都改为了id为0,将cgi程序的执行路径修改为/var/www/cgi-bin,boa默认将/var/www/作为其http服务器根目录,将/var/log/boa/默认作为其日志目录,error_log就会放在这个目录下,用来记录boa服务器的执行和出错信息。
现在配置服务器就完成了。
现在将上位机中/etc/mime.types文件拷贝到下位机中的相应目录。
cp /etc/mime.types /root/nfs/rootfs/etc/
创建配置文件中(boa.conf)指定的各种目录
mkdir /root/nfs/rootfs/var/www
mkdir <span>/root/nfs/rootfs</span>/var/www/cgi-bin
mkdir <span>/root/nfs/rootfs</span>/var/log
mkdir <span>/root/nfs/rootfs</span>/var/log/boa
6.启动boa服务器
开发板上电,进入Linux系统并加载根文件系统(如果你是nfs挂载,那么可以直接进行下面操作;如果是要将内核和文件系统烧写到flash上,那么请先烧写)
在下位机中执行命令:
boa
现在可以查看一下日志,看是否启动成功:
cat /var/log/boa/error_log
如果返回信息和下面类似:
<span style="line-height:1.5;"> boa: server version Boa/0.94.13
<span style="line-height:1.5;"> boa: server built Aug 16 2014 at 00:41:36
<span style="line-height:1.5;"> boa: starting server pid=981, port=80
<span style="line-height:1.5;"> 那么,就说明boa服务器启动成功了。如果出现了其他的错误,那么请看附录。
<span style="line-height:1.5;">
<span style="line-height:1.5;">三、测试boa服务器</span>
<span style="line-height:1.5;">1.测试静态网页文件</span>
<span style="line-height:1.5;"> 文件名:index.html
<span style="line-height:1.5;"> 下面是文件内容:
<span style="line-height:1.5;"> <body>
<span style="line-height:1.5;"> Boa server Test OK!
<span style="line-height:1.5;"> </body>
<span style="line-height:1.5;">
<span style="line-height:1.5;"> 将index.html放到下位机的/var/www/目录下,在浏览器中访问http://下位机ip/index.html,就能看到Boa server Test OK!的字样了。如果不能看到字样,先确认上面所有步骤都是对的,再到附录看一下ip地址的说明。
<span style="line-height:1.5;">
<span style="line-height:1.5;">2.测试CGI程序</span>
<span style="line-height:1.5;"> 文件名:hello.c
<span style="line-height:1.5;"> 文件内容如下:
<span style="line-height:1.5;"> #include <stdio.h>
#include <stdlib.h>
int main (void)
{
printf (“Content-type: text/htmlnn”);
printf (“<html>n<head>n<title>CGI Test</title>n</head>n”);
printf (“<body>n<h1>CGI Test OK!</h1>n</body>n</html>”);
exit (0);
}
<span style="line-height:1.5;">
<span style="line-height:1.5;"> 千万别忘记第一个printf函数后加的两个nn,这是HTTP协议规定的,必须这么写。</span>
<span style="line-height:1.5;"> 用交叉编译工具编译hello.c (下面这两条命令可能需要在上位机中执行,因为下位机可能没安装交叉编译工具)</span>
<span style="line-height:1.5;"> <span style="font-family:Arial;font-size:14px;line-height:26px;background-color:#FFFFFF;">arm-cortex_a8-linux-gnueabi-</span><span style="font-family:Arial;font-size:14px;line-height:26px;background-color:#FFFFFF;">gcc -o hello hello.c</span></span>
<span style="line-height:1.5;"> 裁剪一下hello的大小:</span>
<span style="line-height:1.5;"> <span style="font-family:Arial;font-size:14px;line-height:26px;background-color:#FFFFFF;">arm-cortex_a8-linux-gnueabi-strip hello</span></span>
<span style="line-height:1.5;"> 将hello可执行文件(CGI程序)放到下位机的/var/www/cgi-bin/目录中</span>
<span style="line-height:1.5;"> cp ./hello <span>/var/www/cgi-bin/ (这条语句是在下位机中执行的,在上位机中目录应写为/root/nfs/rootfs/var/www/cgi-bin/)</span></span>
<span style="line-height:1.5;"> 现在通过浏览器浏览:http://下位机ip/cgi-bin/hello,就能看到CGI Test OK!的字样了。如果看不到,请看附录中CGI 502 Gateway错误的说明。</span>
<span style="line-height:1.5;">
<span style="line-height:1.5;">经过上面两部测试,说明boa服务器已经可以工作了。
<span style="line-height:1.5;">
<span style="line-height:1.5;">
四、附录
**错误:**
<span style="color:#323E32;font-family:simsun;font-size:14px;line-height:21px;background-color:#8A8A8A;"><span style="background-color:;"> </span><span style="background-color:;">make: yacc: Command not found</span></span>
make: *** [y.tab.c] Error 127
**解决:**
** **apt-get install bison
安装完成后返回继续make
**
**
**错误:**
** **<span style="color:#323E32;font-family:simsun;font-size:14px;line-height:21px;background-color:#8A8A8A;">make: lex: Command not found</span>
make: *** [lex.yy.c] Error 127
**解决:**
** **apt-get install flex
然后返回继续make
**
**
**错误:执行make命令编译时出现了如下错误:**
<span style="font-family:Arial;font-size:14px;line-height:26px;background-color:#FFFFFF;">util.c:100:1: pasting “t” and “->” does not give a valid preprocessing token</span>
make: *** [util.o] Error 1
**解决:**
在src目录中打开compat.h
vim compat.h
<span style="font-family:Arial;font-size:14px;line-height:26px;background-color:#FFFFFF;">找到</span>
#define TIMEZONE_OFFSET(foo) foo##->tm_gmtoff
修改成
#define TIMEZONE_OFFSET(foo) (foo)->tm_gmtoff
然后
make clean
make
**修改:**
** **打开src/boa.c
注释掉下面两句话:
if (passwdbuf == NULL) {
DIE(”getpwuid”);
}
if (initgroups(passwdbuf->pw_name, passwdbuf->pw_gid) == -1) {
DIE(”initgroups”);
}
为
#if 0
if (passwdbuf == NULL) {
DIE(”getpwuid”);
}
if (initgroups(passwdbuf->pw_name, passwdbuf->pw_gid) == -1) {
DIE(”initgroups”);
}
#endif
修改:src/log.c
vi src/log.c
注释下面的语句
if (dup2(error_log, STDERR_FILENO) == -1) {
DIE("unable to dup2 the error log");
}
**修改:src/boa.c**
vi src/boa.c
注释下面的语句:
if (setuid(0) != -1) {
DIE(”icky Linux kernel bug!”);
}
**静态页面测试时ip地址的说明:**
这个ip地址必须是下位机的ip地址。有些下位机不能自动获取ip地址,需要在u-boot中手动指定,上电下位机,进入u-boot(上电后马上按任意键,停在u-boot设置界面)
setenv bootargs root=nfs nfsroot=上位机ip:/root/nfs/rootfs/ rw init=/linuxrc console=ttySAC0,115200 ip=192.168.2.19
最后的参数ip=192.168.2.19是手动设置的下位机ip地址,当然,这个ip地址是本地地址,只能在当前局域网中访问,在internet中无法访问到。在同一个局域网中的电脑中,使用浏览器访问:http://192.168.2.19/index.html就可以访问静态页面了。
**CGI页面测试时出现502错误的说明:**
** 如果页面出现 502错误和如下的提示:**
#
the cgi was not cgi/1.1 compliant
<span style="line-height:1.5;"> 这说明你的CGI程序输出不符合HTTP协议的规范,最可能出错的地方就是hello.c文件中第一个printf函数最后的两个n没有写或没写对。一定是两个n。</span>
<span style="line-height:1.5;">
**五、参考文章**
** [http://blog.csdn.net/liang890319/article/details/6845030](http://blog.csdn.net/liang890319/article/details/6845030)**
** [http://blog.csdn.net/furtherchan/article/details/5702187](http://blog.csdn.net/furtherchan/article/details/5702187)**
** [http://blog.csdn.net/hongjiujing/article/details/1795941](http://blog.csdn.net/hongjiujing/article/details/1795941)**
** [http://blog.csdn.net/liuzhidong123/article/details/6851955](http://blog.csdn.net/liuzhidong123/article/details/6851955)
**
好了,本文到此为止了。如果遇到不能解决的问题,可以发邮件联系我:xinspace@yeah.net