技术宅,fat-man

增加语言的了解程度可以避免写出愚蠢的代码

导航

ubuntu下使用C语言开发一个cgi程序

主要步骤是:

1. 开发一个C程序(在标准输出中输出HTML字符串)

2. 复制到apache2的cgi-bin目录去

3. 在httpd.conf中开启cgi功能(我似乎没用到,也可以使用cgi)


 

ubuntu上apache的cgi-bin目录上 是/usr/lib/cgi-bin

gcc -o hello hello.c
cp hello /usr/lib/cgi-bin

 

hello.c

#include <stdio.h> 

int main() 
{ 
    printf("Content-type:text/html\n\n"); 
    printf("<html>\n"); 
    printf("<head><title>welcome to c cgi.</title></head>\n<body>"); 
    printf("hello,world!"); 
    printf("</body></html>\n"); 

    return 0;
} 

 

posted on 2014-02-24 19:53  codestyle  阅读(574)  评论(0编辑  收藏  举报