FOX Board G20 technical documentation Buy

Running a CGI written in C

This article illustrates how to config lighttpd web server to run cgi written in C

Hello world example

Save this "Hello world !" source code example in /var/www/cgi-bin (create this directory if it not exists).

#include "stdio.h"
 
int main(void) {
  printf( "Content-Type: text/plain\n\n" );
  printf("Hello world !\n");
  return 0;
}

Compile it typing:

debarm:~# gcc hello.c -o hello.cgi

lighttpd configuration

Change the server.modules list inside /etc/lighttpd/lighttpd.conf in:

server.modules              = (
            "mod_access",
            "mod_cgi",
            "mod_alias",
            "mod_accesslog",
            "mod_compress",
)

and add these lines:

$HTTP["url"] =~ "/cgi-bin/" {
        cgi.assign = ( "" => "" )
}

cgi.assign      = (
        ".cgi"  => ""
)

Restart lighttpd typing:

debarm:~# /etc/init.d/lighttpd restart

Final test

Access with your browser to the FOX Board web page using this URL:

http:///cgi-bin/hello.cgi

Home page FOX Board G20 technical documentation Buy