Wamp 下运行 CGI 笔记

  虽然假期的余额不足了,可是仔细想一想放假又有多少事情能够作呢?休息的差很少了,仍是上班的好,长时间的休息人就废了。赞成的举手,不一样意的就算了。html

 

httpd.conf 的配置apache

  我这里使用的是 Wamp 的 Apache 服务器,其配置在 C:\wamp64\bin\apache\apache2.4.33\conf 目录下,而后修改配置以下:浏览器

LoadModule cgi_module modules/mod_cgi.so

ScriptAlias /cgi-bin/ "${INSTALL_DIR}/cgi-bin/"

#
# "c:/Apache24/cgi-bin" should be changed to whatever your ScriptAliased
# CGI directory exists, if you have that configured.
#
<Directory "${INSTALL_DIR}/cgi-bin">
    AllowOverride None
    Options None
    Require all granted
    Options ExecCGI
    Order allow,deny
    Allow from all
</Directory>

AddHandler cgi-script .cgi

  上面的修改一共是四个部分,并无在一块儿,查找一下便可。修改完配置之后记得重启一下服务器。服务器

 

C 测试代码微信

  修改完 Apache 的配置之后来一段简单的 C 的代码,代码以下:ide

 1 #include <stdio.h>
 2  
 3 void main()
 4 {
 5     printf("\n");
 6     printf("<html><head><title>test</title></head><body>");
 7     printf("<a href=\"www.baidu.com\">test</a>\r\n");
 8     printf("C CGI Test");
 9     printf("</body></html>");
10 }

  代码很简单,我使用的是 VS 的 IDE,所以使用 cl 在命令行下编译一下便可。将编译完的 exe 文件修改成 cgi 的扩展名,放入 CGI 的目录下(我这里是 C:\wamp64\cgi-bin),而后在浏览器中输入地址 http://localhost/cgi-bin/test.cgi 便可。测试

 

运行效果ui

  具体的运行效果就不看了,看一下浏览器中“查看源码”的功能吧,源码以下:spa

1 <html><head><title>test</title></head><body><a href="www.baidu.com">test</a>
2 C CGI Test</body></html>

  效果就是这样了。.net

 

  注意:在 C 的代码中,第一行的换行是必需要的,缘由我也不知道。

 

  记录在此了!

  另外,作一个有节操的人,把参考的两个链接给出,并在此感谢。

1 Apache Web 服务器配置CGI程序,执行Python、Perl脚本 - 哎咿呀 - CSDN博客
2 https://blog.csdn.net/sotower/article/details/41014767
3 
4 Windows下配置Apache运行C语言的CGI脚本 - u013005924的博客 - CSDN博客
5 https://blog.csdn.net/u013005924/article/details/52021152

 


 

个人微信公众号:“码农UP2U”

相关文章
相关标签/搜索