在Apache2 / Redhat5.5上运行Perl脚本

我正在使用Apache2 / Redhat5.5configuration。 我正在尝试configuration(并学习)如何运行对我而言是新的Perl脚本。

在我的httpd.conf文件中,我做了这些更改和/或注意这些设置:

DirectoryIndex index.html index.html.var index.cgi index.pl ... AddHandler cgi-script .cgi .pl ... ScriptAlias /cgi-bin/ "/var/www/cgi-bin/" ... <Directory "/var/www/cgi-bin"> AllowOverride None Options None Order allow,deny Allow from all </Directory> 

我已经把这个脚本放到了/ var / www / cgi-bin /目录下: http : //www.seaglass.com/downloads/file_upload.pl 。

然后,我的浏览器指向myIpAddress / cgi-bin / file_upload.pl并得到“内部服务器错误…服务器遇到内部错误或configuration错误,无法…”

然后我检查错误日志find这个:

 [Sun Nov 27 19:59:02 2011] [error] [client ***] (2)No such file or directory: exec of '/var/www/cgi-bin/file_upload.pl' failed [Sun Nov 27 19:59:02 2011] [error] [client ***] Premature end of script headers: file_upload.pl [Sun Nov 27 19:59:02 2011] [error] [client ***] File does not exist: /var/www/html/favicon.ico 

假设你已经启用了SELinux,打开CGI:

 setsebool -P httpd_enable_cgi on 

这假定脚本上传正确。 如果Perl脚本以DOS格式保存,或者通过二进制模式通过ftp上传,Perl脚本运行得并不顺利。 如果您没有通过ftp(而是scp或sftp)复制文件,请使用以下命令转换文件:

 dos2unix file_upload.pl 

这对我来说听起来像你可能没有在你的机器上安装perl ,或者它可能在一个不同于/usr/bin/perl的path上。 尝试在命令行键入/usr/bin/perl -v以确认perl实际上已经安装。

你也可能在/var/www/cgi-bin/file_upload.pl上丢失执行权限。