CGI

CGI を各ユーザのSites で有効にする。

/etc/httpd/httpd.conf
を書き換えた。
Default では、/Library/WebServer/CGI-Executable においたファイルが有効 と設定してあった。
これを、各ユーザのSites/cgi-bin 内に置いたcgiファイルのみ有効にするとした。
/etc/httpd/httpd.conf
の625行目あたり
## ScriptAlias: This controls which directories contain server scripts. ## ScriptAliases are essentially the same as Aliases, except that ## documents in the realname directory are treated as applications and ## run by the server when requested rather than as documents sent to the client. ## The same rules about trailing “/” apply to ScriptAlias directives as to ## Alias. ## # ScriptAlias /cgi-bin/ “/Library/WebServer/CGI-Executables/” ScriptAlias /cgi-bin/ “/Users/*/Sites/cgi-bin” ## ## This should be changed to whatever your ScriptAliased ## CGI directory exists, if you have that configured. ## # <Directory “/Library/WebServer/CGI-Executables” <Directory “/Users/*/Sites/cgi-bin” # AllowOverride None AllowOverride All Options None Order allow,deny Allow from all </Directory> さらに、このサーバ固有の設定が記入されているファイルを/etc/httpd/sites/ からさがした。
0000_192.168.0.2_80_mike.md.tsukuba.ac.jp.conf である。
このファイルに保護領域の設定が記入されている。
このファイルの22行目あたりは、
   <Directory “/Library/WebServer/Documents”> Options All -Indexes +ExecCGI +Includes +MultiViews # AllowOverride None AllowOverride All <IfModule mod_dav.c> DAV On </IfModule> </Directory> となっている。試行錯誤の結果だ。

CGI がうごいていることの確認

test.cgi というファイルを作成する。内容は、
    #! /usr/bin/perl     print “Content-type: text/plainnn”;     print “Hellow World”;     exit; である。改行はUNIXにすること。

  <a href=”cgi-bin/test.cgi”>Test script</a> とどっかのページに書き。これを表示してクリックすれば Hellow World と表示されたページが出現する。これがうまくいけばいい。

CGI エラーログ
○サーバ管理 ー> Web -> ログ -> アクセス
130.158.152.137 – – [22/Jun/2006:08:41:42 +0900] “GET /terui/cgi-bin/test.cgi HTTP/1.1” 200 24 “-” “Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; ja-JP-mac; rv:1.8.0.4) Gecko/20060508 Firefox/1.5.0.4”
130.158.152.137 – – [22/Jun/2006:08:42:07 +0900] “GET /terui/cgi-bin/light.cgi HTTP/1.1” 404 – “-” “Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; ja-JP-mac; rv:1.8.0.4) Gecko/20060508 Firefox/1.5.0.4”
130.158.152.137 – – [22/Jun/2006:08:42:15 +0900] “GET /terui/cgi-bin/bbs/light.cgi HTTP/1.1” 500 629 “-” “Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; ja-JP-mac; rv:1.8.0.4) Gecko/20060508 Firefox/1.5.0.4”

○サーバ管理 ー> Web -> ログ -> エラー
[Thu Jun 22 08:42:07 2006] [error] [client 130.158.152.137] File does not exist: /Library/WebServer/Documents/error.html
[Thu Jun 22 08:42:15 2006] [error] (2)No such file or directory: exec of /Library/WebServer/Documents/terui/cgi-bin/bbs/light.cgi failed
[Thu Jun 22 08:42:15 2006] [error] [client 130.158.152.137] Premature end of script headers: /Library/WebServer/Documents/terui/cgi-bin/bbs/light.cgi

文法チェック
# perl -wc [ファイル名]
のコマンドでsyntax error をチェックする
Premature end of script headers というエラーは
1行目の#! /usr/bin/perl が誤りである。

Name “main::mode” used only once: possible typo at init.cgi line 125. というエラーがでても気にしない。これは変数に指定してあるが1回しかつかってないけどいいのか? という意味だから
syntax OK となればいい。

apacheの再起動

# /usr/sbin/apachctl restart
/usr/sbin/apachectl restart:httpd restarted