标题:Ubuntu下CGI的安装 出处:刘佳的技术日志、博客 时间:Wed, 18 Jul 2007 16:51:33 +0000 作者:kook 地址:http://www.52zhe.cn/read.php/65.htm 内容: 参考文档: 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:默认虚拟主机修改 AllowOverride None Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch Order allow,deny Allow from all 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 Generated by Bo-blog 2.1.0