LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1709|回复: 3

[求助]怎样配置apache让它支持perl脚本?

[复制链接]
发表于 2010-4-13 23:28:45 | 显示全部楼层 |阅读模式
即用perl来进行cgi开发。想弄个小服务器来试试。但无奈不会弄apache2.
发表于 2010-4-14 14:13:40 | 显示全部楼层
在你的httpd.conf里面添加类似下面的指令
  1. ScriptAlias /cgi-bin/ /path/to/your/cgi script/
复制代码
然后将你的cgi脚本放在/path/to/your/cgi script目录下就行。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2010-4-14 22:40:54 | 显示全部楼层
不行。浏览器提示:
Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, webmaster@localhost and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.
Apache/2.2.8 (Ubuntu) mod_fastcgi/2.4.6 PHP/5.2.4-2ubuntu5.11 with Suhosin-Patch mod_perl/2.0.3 Perl/v5.8.8 Server at localhost Port 80


apache2日志里这样写
[Wed Apr 14 22:36:47 2010] [error] [client 127.0.0.1] (8)Exec format error: exec of '/var/www/cgi-bin/try.cgi' failed
[Wed Apr 14 22:36:47 2010] [error] [client 127.0.0.1] Premature end of script headers: try.cgi

最后,希望你可以给出一个小例子。不胜感激。
回复 支持 反对

使用道具 举报

发表于 2010-4-15 10:45:44 | 显示全部楼层
首先,保证那个cgi脚本对运行apache的用户可执行,可以
  1. chmod a+x xxx.cgi
复制代码

其次,CGI程序,需要先输出一些header,比如Content-Type,然后才是htmll。
用Perl写CGI程序有两种方式,一种,直接print出html
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. print "Content-Type: text/html\n";
  5. print "\n"; #An empty line is required, separate http header and body
  6. print << 'EOF';
  7. <html>
  8.     <head><title>Hello,world!</title></head>
  9.     <body>
  10.         <h1>Hello,world</h1>
  11.     </body>
  12. </html>
  13. EOF
复制代码
注意,确保第一行#!/usr/bin/perl指定了正确的perl解析器位置

另一种,使用CGI模块
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. use CGI qw(:standard);
  5. print header,
  6.     start_html("Hello,world!"),
  7.     h1('Hello,world!'),
  8.     end_html();
复制代码

题外话:写CGI脚本之前,我想你应该知道什么是CGI脚本,它是什么样的执行方式,如果还不清楚,google一下。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表