1、在http://www.boa.org/下载boa(boa-0.94.13.tar.gz),并放到Ubuntu中建立好的文件夹中。
2、解压文件: tar -vxf boa-0.94.13.tar.gz,得到 boa-0.94.13 文件夹。
3、命令:cd boa-0.94.13/src/,进入src/目录中运行./configure生成Makefile文件。
4、在src/目录中修改一下文件:
(1)、将boa.c中的
if(setuid(0) != -1)
{
DIE(”icky Linux kernel bug!”);
}
这三行注释掉,否则后面运行boa会出现“boa.c:226 - icky Linux kernel bug!: No suchfile or directory”错误。
(2)、将compat.h中的
#define TIMEZONE_OFFSET(foo) foo##->tm_gmtoff
改为
“#define TIMEZONE_OFFSET(foo) (foo)->tm_gmtoff
(3)、将defines.h中的 #define SERVER_ROOT “/etc/boa” 修改为 #define SERVER_ROOT “/boa”(这样boa程序启动时会在/boa目录下寻找boa.conf配置文件)
5、在命令行输入:make
ps:这一步刚刚搭建的时候会出现很多错误,把错误复制到网络搜索会找到解决办法,如果没有错误就继续下一步。
6、建立文件夹:在根目录下建立/boa目录并且在boa目录里再建立www、cgi-bin、log文件夹(命令:mkdir -p /boa /boa/www /boa/cgi-bin /boa/log)
7、将需要的文件复制到相应的文件夹里
(1)、将boa-0.94.13/src目录下生成的boa、boa_indexer文件复制到/boa中
(2)、将boa-0.04.13目录下的boa.conf文件复制到/boa中
(3)、将/etc/mime.types复制到/boa目录中
8、修改上一步复制的boa.conf文件,相当于配置boa(已去除文件中的注释部分)
Port 80
User和Group需要修改
User 0
Group 0
在error_log和access_log前面加上路径
ErrorLog /boa/log/error_log
AccessLog /boa/log/access_log
存放HTML文件的根路径
DocumentRoot /boa/www
UserDir public_html
DirectoryIndex index.html
DirectoryMaker /boa/boa_indexer
KeepAliveMax 1000
KeepAliveTimeout 10
MimeTypes /boa/mime.types
DefaultType text/plain
指定传给cgi程序的PATH环境变量
CGIPath /bin:/usr/bin:/usr/local/bin
Alias /doc /usr/doc
boa服务器会到/boa/cgi-bin中寻找xxx.cgi程序。
ScriptAlias /cgi-bin/ /boa/cgi-bin/
对比原来的文件修改其中不同的地方
9、测试
(1)、在/boa/www目录下vim index.html
<html>
<body>
<h3>Hello boa!</h3><br/>
<img src="test.jpg"/>
<h3>Hello ubuntu</h3><br/>
<a href="/cgi-bin/test.cgi">to cgi page</a>
</body>
</html>
test.jpg 图片放在目录/boa/www/中
(2)、在/boa/cgi-bin目录下,vim test.c
include <stdio.h>
int main()
{
printf("Content-type:text/html\n\n");
printf("<html><body>");
printf("<font style=\"color:red; font-size:30px;\">Hello CGI!</font><br/>");
printf("<a href=\"/index.html\">return index.html</a>");
printf("</body></html>");
return 0;
}
ps:重要的事情
一定要注意路径,根据实际路径修改!