Apache2.2 ScientificLinux6.3(Red Hatクローン)でCGIを動かす。
表題の環境でCGIの設定をした時の備忘録。
Perlの確認
などして、Perlがインストールされているかどうか、インストールされている場合のPATHを確認しておく。上記のPATHがデフォルであるから、違う場合はPATHを切っておく。
$ which perl
/usr/bin/perl
$
目的のディレクトリ構造
CGIディレクトリ:/var/www/cgi-bin/Web公開ディレクトリ(DocumentRoot):/var/www/html/
DocumentRoot以下にCGIディレクトリを入れる必要はなく、CGIディレクトリはDocumentRootと同じ階層に入れる。
CGIの実行を許可する
/etc/httpd/conf/httpd.confを編集する。デフォルトでは、AddHandler cgi-script .cgiが#でコメントアウトされているので、この#を外す。
CGIを実行するディレクトリの設定を行う
ScriptAlias /cgi-bin/ /home/httpd/cgi-bin/というのは、「http://×××/cgi-bin/」にアクセスがあったときは、「var/www/cgi-bin」の内容を使うという意味。/etc/httpd/conf/httpd.confの
Optionsディレクティブには他に、
None:オプションを一つも有効にしない
FollowSymlinks:シンボリックリンクの追跡を許可する。
Indexes:デフォルトのindexが存在しない場合に、サーバーによるディレクトリのファイルリスト生成を許可する。
などがある。
# 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/ "/var/www/cgi-bin/"#
# "/var/www/cgi-bin" should be changed to whatever your ScriptAliased
# CGI directory exists, if you have that configured.
#
AllowOverride None
Options ExecCGI
Order allow,deny
Allow from all
CGIの動作確認
viで以下の様な、Perlのテストコードを書く。WebブラウザからURLを叩いて Halo Perlと表示されれば問題ない。
print "Content-type: text/html\n\n";
print "\n";
print "Halo Perl\n";
print "\n";