<Directory /usr/local/apache/cgi-bin/> Require all granted AllowOverride None AddHandler cgi-script .pl .cgi Options +ExecCGI Order allow,deny Allow from all </Directory> 二、测试 http://locahost/cgi-bin/test-cgi打开该地址,测试自己的cgi程序。首先要声明一个点就是 test-cgi必须是可执行程序,注意权限。否则会出现如下错误: 三、应用 编写c程序,输出结果。结果可以是文本、图片、声音等。我在输出图片的时候遇到了错误, printf(“<img src = ”image/***.jpg'>); 这个地方的image目录位于默认根目录/usr/local/apache/htdocs/中,这样写路径会遇到错误。。。改成/image/***.jpg即可。 #include <stdio.h>#include <stdlib.h>#include <sys/types.h>#include <sys/ipc.h>#include <sys/shm.h>#include <string>#include <vector>#include <time.h>#include <set>intmain (int argc, const char* argv[]){ printf ('Content-type: text/html\n\n'); char *query = getenv ('QUERY_STRING'); if(query==NULL) { fprintf(stdout, 'no query submitted.'); return -1; } //添加自己的应用.... return 0;} |
|