开发者

how to run a cgi program

开发者 https://www.devze.com 2023-02-12 14:01 出处:网络
I am new to cgi and with an example I wrote a small program in c++ which I have compiled to a .cgi file.

I am new to cgi and with an example I wrote a small program in c++ which I have compiled to a .cgi file.

My question is: do I need an separate web server? I have lighttpd as my default web server ... If i can run thought lighttpd please explain ho开发者_C百科w can I do it...


  1. Make sure your .cgi file is executable, and put it under your web root.
  2. Turn on cgi http://redmine.lighttpd.net/wiki/1/Docs:ModCGI
  3. go to the page. :)


Strictly speaking you don't need a server. If you just want to see your CGI running, you can use my tiny runCGI project.

All you need is to set a yaml file which looks something like this

_exec: /var/cgi-bin/myfile.cgi
method: GET
query_string:
  q: s

and then run

./runCGI myyamlfile.yaml

You will see the output on the console's standard output.

You can even debug it with gdb, debug runCGI gdb runCGI, run with the correct parameters (run someyaml.yaml), issue tcatch exec (tcatch catches it only once) and then set breakpoints to your CGI file:

$ g++ a.cc -o a.out
$ cat a.yaml
method: GET
_exec: a.out
$ gdb runCGI
GNU gdb 6.8-debian
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu"...
(gdb) tcatch exec
Catchpoint 1 (exec)
(gdb) run a.yaml
Starting program: /home/elazar/runCGI/runCGI a.yaml
Executing new program: /home/elazar/runCGI/a.out
0x00007fc3a24a6a60 in ?? () from /lib64/ld-linux-x86-64.so.2
(gdb) tbreak main
Breakpoint 2 at 0x400577: file a.cc, line 2.
(gdb) c
Continuing.
main (argc=1, argv=0x7fff14891408) at a.cc:2
2       int a =0;
(gdb)
0

精彩评论

暂无评论...
验证码 换一张
取 消