2.Perlの確認
サーバー・コンソールあるいはtelnetクライアントなどからPerlの動作確認が出来ます。バージョン確認も可能ですので是非覚えて下さい。
Perlが動作しているか、またバージョンはいくつかを確認する際のコマンドです。
[root@server /root]# perl -v
This is perl, version 5.005_03 built for i386-linux
Copyright 1987-1999, Larry Wall
Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5.0 source kit.
Complete documentation for Perl, including FAQ lists, should be found on
this system using `man perl' or `perldoc perl'. If you have access to the
Internet, point your browser at http://www.perl.com/, the Perl Home Page.
[root@server /root]#
--------------------------------------
通常CGIスクリプトでは、先頭行に
#!/usr/local/bin/perl
などと、Perlインタープリターへのパスを指定しています。このパスはマシンによって異なる可能性がありますので、必ず確認します。
[root@server /root]# which perl
/usr/bin/perl
[root@server /root]#
これでスクリプトの1行目には#!/usr/bin/perlと記述すれば良いことが解ります。
3.CGIを有効にする設定
Apacheの設定の中でCGIのディレクトリを設定する必要があります。
[root@server /root]# vi /usr/local/etc/apache/httpd.conf
--------------------------------------
# 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/ "/usr/local/www/cgi-bin/" ←サイトでのCGI実行ディレクトリ
個人のCGI実行ディレクトリは、上記の記述に続けて
ScriptAlias /~nakayama/cgi-bin/ "/home/nakayama/www/cgi-bin/"
ScriptAlias /~yamamoto/cgi-bin/ "/home/yamamoto/www/cgi-bin/"
と記述します。
ただし、これでは設定したディレクトリに配置するすべてのファイルを実行ファイルとして認識してしまいます。そのため、ファイル拡張子によって実行ファイルかどうかを切り分けて判別する必要があります。
--------------------------------------
# AddHandler allows you to map certain file extensions to "handlers",
# actions unrelated to filetype. These can be either built into the server
# or added with the Action command (see below)
#
# If you want to use server side includes, or CGI outside
# ScriptAliased directories, uncomment the following lines.
#
# To use CGI scripts:
#
AddHandler cgi-script .cgi ←行頭の#を消して設定を有効にします。
--------------------------------------
4.Apcheを再起動します。
[root@server /root]# /etc/rc.d/init.d/httpd restart
トップへ戻る
13/January/2000