在Apache2/Redhat5.5上執行Perl腳本

在Apache2/Redhat5.5上執行Perl腳本

我正在使用 Apache2/Redhat5.5 配置。我正在嘗試配置(並學習)如何運行 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>

我已經放置了這個腳本:http://www.seaglass.com/downloads/file_upload.pl進入 /var/www/cgi-bin/ 目錄。

然後,我將瀏覽器指向 myIpAddress/cgi-bin/file_upload.pl 並收到“內部伺服器錯誤...伺服器遇到內部錯誤或設定錯誤,無法...”

然後我檢查錯誤日誌以找到以下內容:

[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

答案1

假設您啟用了 SELinux,請使用下列命令開啟 CGI:

setsebool -P httpd_enable_cgi on

這假設腳本已正確上傳。如果 Perl 腳本以 DOS 格式儲存或透過 ftp 以二進位模式上傳,則它們運作得不好。如果您沒有透過 ftp(而是 scp 或 sftp)複製文件,請使用下列命令轉換文件:

dos2unix file_upload.pl

答案2

對我來說,這聽起來像是您可能沒有perl安裝在您的電腦上,或者它可能位於與/usr/bin/perl.嘗試/usr/bin/perl -v在命令列中輸入以確認 perl 確實已安裝。

您也可能缺少 的執行權限/var/www/cgi-bin/file_upload.pl

相關內容