====== CGIの実行環境 ======
[[ubuntu:server:site|静的サイトの作成]]で設置した「peconet.localsite」をドキュメントルートとした設定を行っています。
----
===== はじめに(設定環境) =====
[[:ubuntu:server#はじめに(環境)|このローカルサーバー構築での基本的な設定項目です。各々の環境で任意に変更します。]]
===== Perlの確認 =====
Ubuntuにおいてはデフォルトでインストールされていますが、Perlを確認できなければインストールします。
$ perl -v\\
インストールされていれば以下のような表示がされます。
This is perl 5, version 38, subversion 2 (v5.38.2) built for x86_64-linux-gnu-thread-multi
(with 44 registered patches, see perl -V for more detail)
Copyright 1987-2023, 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 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 https://www.perl.org/, the Perl Home Page.\\
Perlのバージョンが確認できなければインストールします。
$ sudo apt install perl\\
==== Perlのパスの確認 ====
peconet@Ubuntu-V:~$ which perl
/usr/bin/perl\\
===== Apacheへ設定する =====
「**$ sudo a2enmod cgid
$ sudo vim /etc/apache2/conf-available/peconet-cgi.conf\\
新規作成したファイルに以下のように記述して保存して閉じる。
\\
==== 設定ファイルの有効化 ====
$ sudo a2enconf peconet-cgi.conf
==== サイトの設定ファイルへも追加の記述 ====
/etc/apache2/sites-available/peconet.localsite.confに
を記述する。
Apacheを再起動する。
$ sudo systemctl restart apache2\\
----
===== CGIの動作確認 =====
==== Perlのサンプルファイルを作成 ====
簡単なPerlプログラムを記述してブラウザでアクセスして動作確認します。\\
サンプルファイル「perl-test.pl」をドキュメントルートに新規作成します。
$ sudo vim /var/www/peconet.localsite/perl-test.pl\\
新規作成したファイルに以下のように記述して保存して閉じます。
#!/usr/bin/perl
print "Content-type: text/html \n\n\n";
print "\\
新規作成したファイルのパーミッションを変更します。
Peconet.Localsite
";
print "Hello..Perl is Working!!
";$ sudo chmod 775 /var/www/peconet.localsite/perl-test.pl\\
==== ブラウザで動作確認 ====
ブラウザで「**
#!/usr/bin/perl --
print "Content-type: text/html \n\n\n";
print "
これはダウンロードしたPerlプログラムなどもそうですが、1行目のPerlパスの指定に...
Peconet.Localsite
";
print "Hello..Perl is Working!!
";
※「--」を追加する #!/usr/bin/perl --**おまじない** 詳細不明ながら、こうすると動作することが多い ===== 関連項目 ===== [[:cafelog|CGIブログシステム Cafelog(メモ)]] [[:tegalog|CGIマイクロブログシステム てがろぐ(メモ)]] ---- ~~socialite~~