c/c++写cgi之helloworld

最近比较闲,所以又回头来学习下c/c++, 但看来看去也没什么好学的,没什么项目,光学一门语言确实没什么好看的,那就来用c/c++写个cgi来玩玩吧,之前没做过cgi,所以这样就既可了解cgi又可复习c/c++了。

先来个c/c++的cgi hello world吧,本人是在apache下运行的啊

新建文件hello.c

#include <stdio.h>
main() {
    printf("Content-type:text/html\n\n");
    printf("Hello,World!");
}

用命令$gcc –o hello hello.c 生成 hello

然后查看apache配置文件httpd.conf, 设置为:[默认的差不多就是这样]

ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
<Directory "/var/www/cgi-bin">
    AllowOverride All
    Options ExecCGI
    Order allow,deny
    Allow from all
</Directory>

然后把生成的hello复制到 /var/www/cgi-bin/下,如果修改了配置的话,就先重起apache, 这时输入http://localhost/cgi-bin/hello,就应该可以看到结果了

2 thoughts on “c/c++写cgi之helloworld”

  1. Hey there, You’ve performed an incredible job. I’ll certainly digg it and in my opinion suggest to my friends. I’m confident they will be benefited from this web site.

Comments are closed.