HTML与CGI如何协作
服务器上执行的 CGI 程序主要负责处理表单,如注册表单或购物单。
首先你需要安装apache服务器:yum install httpd
然后就是修改你的apache的文件httpd.conf:
Relax access to content within /var/www.
#
<Directory "/home/wuyong/perlProjects/vmcrud/View/cgi-bin">
ScriptAlias /cgi-bin/ "/home/wuyong/perlProjects/vmcrud/View/cgi-bin/"
<Directory "/home/wuyong/perlProjects/vmcrud/View/cgi-bin">
然后就是一个通讯的流程图了:
然后你的执行的cgi代码必须在你的cgi-bin的文件夹下,实例代码如下:
#!/usr/bin/perl #这行必须有,否则浏览器无法解释
use strict;
use warnings;
print "Content-type:text/html\r\n\r\n"; #这是MIME的头部告诉浏览器 MIME 首部(MIME header)。不管使用的是哪一种编程语言,CGI 程序的第一 行输出都必须是一个 MIME 首部,其后必须跟随两个换行符。本行负责说明程序会发送哪种 类型的数据。在这里, CGI 脚本将把 HTML 文本发送回服务器。\n\n 说明打印一个空行。为 了成功运行 CGI 程序,这个空行也是非常重要的。所有首部都要求在文档内容前提供一个空行。
print '<html>';
print '<head>';
print '<meta charset="utf-8">';
print '<title>welcome to vm and storage create update delete check</title>';
print '</head>';
print '<body>';
print '<h2>Hello Word! </h2>';
print '<button>Hello Word! </button>';
print '<p>this is the first cgi</p>';
print '</body>';
print '</html>';
添加附加组将apache添加到我们的wheel组中
usermod -G wheel apache