一、下载源码
官网: http://embedthis.com/
二、解压编译
# tar -zxvf goahead-3.6.4.tar.gz
# cd goahead-3.6.4
# make CC=arm-linux-gcc ARCH=arm或(configure && make)
编译完成后进入linux-arm-default/bin生成可执行文件
三、拷贝文件
将bin目录下的可执行文件goahead,库文件libgo.so拷贝到开发板
库文件可与goahead文件放在同一目录下,也可拷贝到开发板/lib 目录下
四、问题(
红色为我遇到的问题)
问题一(运行错误):
goahead: 0: Can't get host address for host dvr: errno 110
goahead: 0: Can't initialize server. Exiting.
解决办法:修改 /usr/src/goahead-3.1.3-0/src/http.c
# vi src/http.c // 共有2处相同的代码需修改
=============================================================================
if ((hp = gethostbyname(host)) == NULL) {
error("Can't get host address for host %s: errno %d", host, errno);
return -1;
}
memcpy((char*) &intaddr, (char *) hp->h_addr_list[0], (size_t) hp->h_length);
ddr = inet_ntoa(intaddr);
websSetIpAddr(ipaddr);
websSetHost(ipaddr);
=============================================================================
改为:
=============================================================================
#if 0
if ((hp = gethostbyname(host)) == NULL) {
error("Can't get host address for host %s: errno %d", host, errno);
return -1;
}
memcpy((char*) &intaddr, (char *) hp->h_addr[0], (size_t) hp->h_length);
ipaddr = inet_ntoa(intaddr);
#else
int sockfd;
struct sockaddr_in sin;
struct ifreq ifr;
sockfd = socket(AF_INET, SOCK_DGRAM, 0);
if (sockfd == -1)
{
return -1;
}
strncpy(ifr.ifr_name, "eth0", IFNAMSIZ);
ifr.ifr_name[IFNAMSIZ - 1] = 0;
if (ioctl(sockfd, SIOCGIFADDR, &ifr) < 0)
{
return -1;
}
memcpy(&sin, &ifr.ifr_addr, sizeof(sin));
ipaddr=inet_ntoa(sin.sin_addr);
#endif
websSetIpAddr(ipaddr);
websSetHost(ipaddr);
=============================================================================
! 修改源码后需重新编译,并下载到开发板
------------------------------------------------------------------------------------------
问题二(运行错误):
goahead: 0: Can't open config file route.txt
goahead: 0: Can't initialize server. Exiting.
解决办法:把 route.txt 拷贝到goahead可执行文件同一目录下。
------------------------------------------------------------------------------------------
问题三(运行错误):
goahead: 0: Can't open config file auth.txt
goahead: 0: Can't load auth.txt
解决办法:在goahead可执行文件同一目录下创建auth.txt。
# touch auth.txt
------------------------------------------------------------------------------------------
问题四:页面存放路径?
答:在goahead可执行文件目录下的web目录,自行创建web目录即可。
# mkdir web
------------------------------------------------------------------------------------------
问题五:CGI存放路径?
答:
1. 修改源码,使错误信息能正确显示(可选)
# vi src/cgi.c +93
error("Cannot find CGI program: ", cgiPath);
修改为:
error("Cannot find CGI program:
%s", cgiPath);
! 修改源码后需重新编译,并下载到开发板
2. 创建cgi-bin目录
# mkdir web/cgi-bin
3. 修改配置文件
# vi route.txt
route uri=/cgi-bin
dir=cgi-bin handler=cgi
修改为:
route uri=/cgi-bin
dir=/opt/linux-arm-default/bin/web handler=cgi // dir设置为web目录的绝对路径
4.
重启goahead
问题六: goahead:Unable to read key self.key Cannot initialize server. Exiting.
goahead: 0: Unable to read key self.key
goahead: 0: Cannot initialize server. Exiting.
安装 goahead 3.6.3 出现了以上问题
解决办法:
在goahead执行文件目录中找到self.key和self.crt文件拷贝到/etc/goahead下
- 测试
1. 创建 index.html (保存至web/index.html)
GoAhead Test Page
Hello, GoAhead!
----------------------------------------------------------------------
2. 创建 test.cgi (保存至web/cgi-bin/test.cgi)
#!/bin/sh
echo
echo Content-type: html/plain
echo
echo `/bin/date`
! 创建完成后赋予该文件可执行权限:
# chmod a+x web/cgi-bin/test.cgi
----------------------------------------------------------------------
3. 启动goahead(如果上面的操作全部已经完成了但依然无法启动goahead,则可尝试cd到goahead所在的目录再尝试启动),在浏览器中输入192.168.1.239/index.html(笔者开发板的IP地址为192.168.1.239),然后在显示的页面中点击“ok”,如果能够正确显示系统时间则说明goahead移植成功且已正确配置。
点击“ok”按钮后: