goahead 移植与配置 [2013-12-18更新]

- 基本步骤

1. 在官网下载最新的源码包
    官网: http://embedthis.com/downloads/index.html

2. 解压并编译
# tar -zxvf goahead-3.1.3-0-src.tgz -C /usr/src
# cd /usr/src/goahead-3.1.3-0
# make CC=arm-arago-linux-gnueabi-gcc ARCH=arm
编译完成后会在 /usr/src/goahead-3.1.3-0/linux-arm-default/bin 生成可执行文件

3. 将bin目录下的可执行文件goahead,库文件libest.so、libgo.so拷贝到开发板
    库文件可与goahead文件放在同一目录下,也可拷贝到 /usr/lib 目录下

但是,goahead移植没那么简单,此时直接运行goahead会有问题,下面将介绍如何逐一解决。



- 移植配置

问题一(运行错误):
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.

解决办法:把 /usr/src/goahead-3.1.3-0/src/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



- 测试

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移植成功且已正确配置。



goahead 移植与配置 [2013-12-18更新]_第1张图片

点击“ok”按钮后:


goahead 移植与配置 [2013-12-18更新]_第2张图片



参考资料: http://www.2cto.com/kf/201310/252154.html



你可能感兴趣的:(Linux,软件安装配置)