Apache 1.3.27 設定メモ2(2002/11/09) 
 

HTML, cgi の動作確認の前に・・・・

これまで簡単にインストールした Apache ですが、あと少しだけ設定が必要です。そうしないと快適な環境に使用することができません。

httpd.conf の設定

Apache をデフォルトでインストールしたディレクトリ(C:\Program Files\Apache Group\Apache\conf)下にある httpd.conf ファイルを修正します。Apache HTTP Server メニューからでも編集することができます・・・が

<Directory "C:/Program Files/Apache Group/Apache/htdocs">
    Options Indexes FollowSymLinks MultiViews ExecCGI   ← ExecCGI を追加します
    AllowOverride All      ← None を All に変更します
    Order allow,deny
    Allow from all
</Directory>

# To use CGI scripts:
AddHandler cgi-script .cgi    ← #を削除します
AddHandler cgi-script .pl    ← 追加します

htdocs に ExecCGI 実行権限をつけるなんて恐ろしい・・・・。わかってますって。ここでは、テストだけのために付けてみました。実際に動かすためには、下記の様に設定するのがいいでしょう。

DocumentRoot "C:/Program Files/Apache Group/Apache/htdocs"
<Directory "C:/Program Files/Apache Group/Apache/htdocs">
    Options Indexes FollowSymLinks MultiViews
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>

# To use CGI scripts:
AddHandler cgi-script .cgi ← #を削除します
AddHandler cgi-script .pl ← 追加します

ScriptAlias /cgi-bin/ "C:/Program Files/Apache Group/Apache/cgi-bin/"
<Directory "C:/Program Files/Apache Group/Apache/cgi-bin">
    AllowOverride All
    Options ExecCGI
    Order allow,deny
    Allow from all
</Directory>

設定が終わったら Apache を再起動させましょう。

HTMLの動作確認

httpd.con の DocumentRoot で指定されているディレクトリ以下に、下記の内容で test.html ファイルを作成します。

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=s-jis">
</head>
<body>
ちゃんと表示されたかな??<br>
<a href="/cgi-bin/test.cgi">cgiの動作テストリンク♪</a><br>
</body>
</html> 

ブラウザを起動し、下記のurlを入力しましょう。ちゃんと表示されれば ok です。

http://localhost/test.html

cgi の動作確認

httpd.con の ScriptAlias /cgi-bin/ で指定されているディレクトリ以下に、下記の内容で test.cgi ファイルを作成します。

#!C:/perl/bin/perl

print "Content-type:text/html\n\n";
print "<html>\n";
print "<body>\n";
print "おす♪ cgi動いたぞ!<br>\n";
print "</body>\n";
print "</html>\n";

ブラウザを起動し、下記のurlを入力しましょう。ちゃんと表示されれば ok です。

http://localhost/cgi-bin/test.cgi

html, cgi の動作確認

ここまでちゃんと動いたら、あと少しです。連携テストをしてみましょう。ブラウザを起動し、下記のurlを入力しちゃんと表示され、リンク先の cgi も動作すれば ok です。

http://localhost/cgi-bin

おつかれさまでした (^_^)v