小弟近日很想親近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]
想在apache裡使用perl寫的cgi...
版主: bryanchang、digdog、謝孟叡
小弟我沒有在 Apache 上使用過 cgi,提供一點查詢到的資料。
不知道您如果不是使用瀏覽器開啟 cgi 而是一般網頁的話是不是也有權限問題呢?
我查到的資訊是說:
/usr/local/apache/cgi-bin <=== 內定放置 cgi 的目錄
/usr/local/apache/htdocs <=== 內定放置首頁的目錄
這兩個目錄的權限,要設定成 755 或是 744 的權限才可以正常在瀏覽器上面瀏覽。
您有提到您對自己撰寫的 cgi 檔案修改了權限,不知道是不是連所在目錄都要呢~
不知道您如果不是使用瀏覽器開啟 cgi 而是一般網頁的話是不是也有權限問題呢?
我查到的資訊是說:
/usr/local/apache/cgi-bin <=== 內定放置 cgi 的目錄
/usr/local/apache/htdocs <=== 內定放置首頁的目錄
這兩個目錄的權限,要設定成 755 或是 744 的權限才可以正常在瀏覽器上面瀏覽。
您有提到您對自己撰寫的 cgi 檔案修改了權限,不知道是不是連所在目錄都要呢~
【老地方神聖狂吃團之狂吃客】
http://flickr.com/photos/xx3734
http://flickr.com/photos/xx3734
謝謝您的回應與指導...詹姆士 寫: /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
我改變了一些設定成功了好幾次之後終於弄出這個:
換句話說,問題出在test.cgi本身,檢查看看囉
很簡單,在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.
換句話說,問題出在test.cgi本身,檢查看看囉
