Ubuntu下CGI的安装

[| 不指定 2007/07/18 16:51]
| |
参考文档:
http://www.kingmx.com/Manual/ApacheMenu/howto/cgi.html
http://forum.ubuntu.org.cn/about60473.html&sid=ba2da03f87e156f358667ad6a4741f3c
第二篇文档代码那里有错误。请参照第一个文档的代码。先解决这个错误。
错误提示:apache 的日志显示 “Premature end of script headers”

#!/usr/bin/perl
print "Content-type: text/html\n\n";
print "Hello, World.";

引用

即使不熟悉Perl语言,你也应该能看出它干了什么。第一行,告诉Apache这个文件可以用/usr/bin/perl(或者任何你正在使用的shell)解释并执行。第二行,打印上述要求的内容类型说明,并带有两个换行,在头后面留出空行,以示HTTP头的结束。第三行,打印文字"Hello, World."。程序到此结束。


安装过程参考:
I:安装模块

sudo apt-get install libapache2-mod-perl2


II:修改apache2.conf,
将原

#AddHandler cgi-script .cgi

修改为

AddHandler cgi-script .cgi .pl


III:默认虚拟主机修改

       <Directory "/home/cgi-bin">
               AllowOverride None
               Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
               Order allow,deny
               Allow from all
       </Directory>


VI:编写第一个CGI程序

root@kook:/home/cgi-bin# cat > /home/cgi-bin/helloworld.pl << EOF
#!/usr/bin/perl
print "Content-type: text/html\n\n";
print "Hello, World.";
EOF


V:查看效果,访问http://127.0.0.1/cgi-bin/helloworld.pl


本文链接:http://www.52zhe.cn/read.php/65.htm
本文作者:kook(若就博客内所涉及的技术问题交流,请用下面的MSN或Gmail联系我)
联系方式:(MSN:kook#live.com) (Google talk:kookliu)
没有版权:GNU,转载时请注明“转载人”欠本人一顿饭,来日见面之时兑现!谢谢合作!
by kook | 分类: Ubuntu | 评论(2) | 引用(0) | 阅读(2236)
Lilith
2007/07/24 09:08
嗯,Bash都可以写CGI,但是没有mod_bash吧。

mod_perl是为了能调用Apache内部对象(即Apache API)的动态站点准备的,如Slash系统。而CGI本身是个通用的接口,不管底下的代码是用什么语言写的,只要输出信息符合CGI和HTML标准就能构成有效的Web体验,静态动态皆可,但它不能直接访问Apache的内部对象。
Lilith
2007/07/19 08:27
运行这种CGI程序不需要mod-perl的,只要mod-cgi就行了。
kook 回复于 2007/07/19 08:38
呵呵,不直呼名字了,lilith,这个如果只安装cgi,是无法应用perl脚本运行的Cgi程序吧。可能是我没有完全写明白。
分页: 1/1 第一页 1 最后页
发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   游客无需密码
网址   电邮   [注册]