2012-10-25 119 views
0

我有奇怪的問題,cgi perl腳本無法正常工作,只有cgi bash腳本正在工作?從瀏覽器

命令行CGI的bash腳本和CGI Perl腳本正在,但只有CGI的bash腳本正在努力,而不是和CGI Perl

從瀏覽器訪問cgi perl腳本後我得到500內部服務器錯誤

and apache error log says 

[Thu Oct 25 01:58:59 2012] [error] [client x.x.x.x] (13)Permission denied: exec of '/home/x/x/x/x/public_html/cgi-bin/test.cgi' failed 
[Thu Oct 25 01:58:59 2012] [error] [client x.x.x.x] Premature end of script headers: test.cgi 

我想從瀏覽器運行cgi perl腳本。

我該怎麼做。

[[email protected] ~]# which perl 
/usr/bin/perl 

[[email protected] cgi-bin]# perl test.cgi 
Content-type: text/plain 

testing... 

test.cgi源

#!/usr/bin/perl 

print "Content-type: text/plain\n\n"; 
print "testing...\n"; 

感謝您的時間。

它是一個專用的服務器和Apache 2

+2

確保Web服務器的用戶標識已讀取並執行對'test.cgi'路徑中所有內容的權限。 – Barmar

+0

嘗試'蘇WWW-data'(或任何的apache用戶),*然後*運行腳本,看看它是否工作。 – January

+0

su apache無法正常工作,所以我將httpd.conf中的用戶和組更改爲cgi文件的所有者,並且所有的工作都完美無缺。,非常感謝,現在我該如何爲用戶apache添加權限以訪問.cgi文件 – AMB

回答

0

檢查哪個用戶正在通過

[[email protected] ~]# top | grep httpd 
15607 apache 16 0 210m 19m 4228 S 23.5 0.2 0:00.52 httpd 

在上面的apache的用戶正在運行運行的httpd。

試蘇阿帕奇,

確認您是通過使用命令WHOAMI APACHE,

如果您還沒有

切換到阿帕奇那麼這意味着沒有外殼被分配給用戶的Apache,

現在修改/ etc /從

/bin/false 

to 

/bin/bash 
passwd文件

查找用戶的Apache和結束 變化

保存passwd文件,然後嘗試su apache,檢查whoami, 如果您成功切換到用戶apache,然後轉到腳本所在的目錄並嘗試從那裏運行它。

,你會得到類似

bash: /usr/bin/perl: Permission denied 

這意味着用戶「阿帕奇」沒有權限用戶的Perl。

你需要添加權限來執行perl腳本給用戶「apache」。

***不要忘記像以前一樣更改passwd文件。

您可以通過將組添加到特定用戶並更改組名稱httpd.conf來實現此目的。

謝謝

1

你的Perl腳本正確設置權限? 將它們與您爲bash腳本設置的權限進行比較。

也許chmod 755,將有助於爲建議here(不幸的是德文)

+0

yes我已經雙重檢查了權限和所有者和grooup和chmodded + X太,仍是CGI bash腳本正在和CGI的Perl的arent在瀏覽器中運行。感謝 – AMB

2

正如Barmar提到的,你可能有一個權限問題。此外,由於你是剛剛起步,這裏是一個改進的測試腳本:

#!/usr/bin/perl 
use strict; 
use warnings; 

#Useful for testing: Perl error messages, plus your die statements, will get 
#sent to the browser. Otherwise you will just see "Internal Server Error". 
use CGI::Carp qw/fatalsToBrowser/; 

#Always use the CGI module for your scripts. 
use CGI; 

#Create simple HTML output (taken directly from CGI documentation). 
my $q = CGI->new;     # create new CGI object 
print $q->header,     # create the HTTP header 
     $q->start_html('hello world'), # start the HTML 
     $q->h1('hello world'),   # level 1 header 
     $q->end_html;     # end the HTML 

請參閱documentation on CGI以獲取更多信息。

此外,爲了澄清:「腳本頭過早結束」錯誤意味着您的腳本沒有向瀏覽器發送任何輸出。在這種情況下,這是因爲你的腳本沒有運行。但是,如果您的腳本運行但實際上並未發送任何輸出,也可能發生這種情況。瞭解這是一個有用的錯誤。

+0

我從你的數據和chmod + x和755也給它創造了新的測試腳本,但仍然在命令行中得到同樣的錯誤,它的運行而不是從瀏覽器,需要的mod_perl運行的Perl CGI腳本?謝謝 – AMB

+0

我剛剛檢查了德國文章,並使用unix格式創建了一個新文檔,以確保安全,並且得到了相同的錯誤。謝謝 – AMB

+0

@AmbroseBwangatto,'mod_perl'不是必需的(如果您剛入門,不推薦使用mod_perl) 。看看這個鏈接更多可能的錯誤來源:http://kurinchilamp.kurinchilion.com/2009/08/permission-denied-exec-of-failed-in-apache-server.html – dan1111