想在apache裡使用perl寫的cgi...

Mac OS X 平台上程式設計的相關問題討論

版主: bryanchangdigdog謝孟叡

回覆文章
內容
發表人
cnboy
新生訓練中
文章: 4
註冊時間: 10/19/2006 11:51 am

想在apache裡使用perl寫的cgi...

#1 文章 cnboy »

小弟近日很想親近perl,所以想在apache裡使用perl寫的cgi...
我看了冰果室裡apache,perl,cgi等關鍵字的文章,實做後還是碰到一些問題,如下...

寫了一個test.cgi
#!/usr/bin/perl -w
print "Content-type: text/html\r\n\r\n";
print "Hello, World.\n";

我改了apache的 httpd.conf
<Directory "/Library/WebServer/CGI-Executables">
...
Options ExecCGI
...
</Directory>

chmod 755 test.cgi 也作了,甚至777也試過了

結果test.cgi能在 Terminal 裡執行,可以看到 Hello,World
但在 safari 卻回應...
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, [no address given] 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/1.3.33 Server at joshdediannao.local Port 80

查了 /private/var/log/httpd/error_log 如下..
[Thu Oct 19 11:10:14 2006] [error] (8)Exec format error: exec of /Library/WebServer/CGI-Executables/test.cgi failed
[Thu Oct 19 11:10:14 2006] [error] [client 127.0.0.1] Premature end of script headers: /Library/WebServer/CGI-Executables/test.cgi

望前輩高手能指點一下
謝謝[/b]
頭像
詹姆士
討論區管理員
文章: 2894
註冊時間: 04/22/2005 7:51 pm
來自: 台北
聯繫:

#2 文章 詹姆士 »

小弟我沒有在 Apache 上使用過 cgi,提供一點查詢到的資料。

不知道您如果不是使用瀏覽器開啟 cgi 而是一般網頁的話是不是也有權限問題呢?
我查到的資訊是說:
/usr/local/apache/cgi-bin <=== 內定放置 cgi 的目錄
/usr/local/apache/htdocs <=== 內定放置首頁的目錄

這兩個目錄的權限,要設定成 755 或是 744 的權限才可以正常在瀏覽器上面瀏覽。
您有提到您對自己撰寫的 cgi 檔案修改了權限,不知道是不是連所在目錄都要呢~
【老地方神聖狂吃團之狂吃客】
http://flickr.com/photos/xx3734
cnboy
新生訓練中
文章: 4
註冊時間: 10/19/2006 11:51 am

#3 文章 cnboy »

詹姆士 寫: /usr/local/apache/cgi-bin <=== 內定放置 cgi 的目錄
/usr/local/apache/htdocs <=== 內定放置首頁的目錄
這兩個目錄的權限,要設定成 755 或是 744 的權限才可以正常在瀏覽器上面瀏覽。
您有提到您對自己撰寫的 cgi 檔案修改了權限,不知道是不是連所在目錄都要呢~
謝謝您的回應與指導...

在httpd.conf裡的
ScriptAlias /cgi-bin/ "/Library/WebServer/CGI-Executables/"
檢查了/CGI-Executables/ 這個目錄如下..
:/Library/WebServer josh$ ls -laF
drwxrwxr-x 6 root admin 204 Oct 19 12:05 ./
drwxrwxr-t 50 root admin 1700 Oct 19 00:40 ../
-rw-rw-r-- 1 josh admin 6148 Oct 19 03:14 .DS_Store
drwxrwxr-x 6 root admin 204 Oct 19 11:23 CGI-Executables/
所以權限應該沒問題。

但http://127.0.0.1/cgi-bin/test.cgi
結果還是...
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, [no address given] 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/1.3.33 Server at joshdediannao.local Port 80
頭像
進藤光
冰果室元老
文章: 3205
註冊時間: 03/16/2005 5:18 pm
來自: insoler.com
聯繫:

#4 文章 進藤光 »

圖檔

我來幫忙貼圖... :lol: :lol: :lol:
世界初、支援RAW相片上傳、分享、學習交流的 insoler • 社群網站https://www.insoler.com
攝影書:「美食写真の達人」進藤ヒカル・著
DJYANG
常吃冰
文章: 257
註冊時間: 03/19/2002 1:01 am
來自: USA/BOSTON

#5 文章 DJYANG »

我改變了一些設定成功了好幾次之後終於弄出這個:
Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, [no address given] 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.
很簡單,在test.cgi第一行的井字號前加個空格就可以了。

換句話說,問題出在test.cgi本身,檢查看看囉
cnboy
新生訓練中
文章: 4
註冊時間: 10/19/2006 11:51 am

#6 文章 cnboy »

很簡單,在test.cgi第一行的井字號前加個空格就可以了。
換句話說,問題出在test.cgi本身,檢查看看囉

真的加個空,就 Internal Server Error ...
但我的問題不是這回事 :cry:

到處爬文,真不知那錯了,決定重頭來過
結果..成了 :lol:

謝謝詹姆士D,JYANG,進藤光諸位大哥的指導
在其中繞了幾圈,漸漸也摸出了pc轉到mac的道
這一小步讓我更愛Mac了..
回覆文章