1. PHPのインストールと設定
  2. 参考
    Puppyの hiawathaには初期から Perlはインストールされているが、phpは関連のパッケージをインストールしないと使えない。(xamppは最初からphpも利用可だった)
    phpを実行するためには PPMで php_7.4+75 / php-cgi_7.4+75 / php-fpm_7.4+75 / libfcgi-binをインストールする。
    さらに phpの実行には必要ないが、途中経過を確認するために systemctl も入れる。 全てのパッケージをインストールしたら /etc/hiawatha/hiawatha.conf の修正をするが、その前に ターミナルから # ip addr を実行してマシンのローカル IPアドレス(192.168.xx.xxx)を取得して 該当個所2ヶ所を書き換える。
    (インターネット設定で DHCPを設定していると、起動の度にローカル IPアドレスが変わる可能性がある。 これを防ぐには固定 IPアドレスを設定しておくと、常に IPアドレスが変わらない。)
    ServerId = webuser
    ConnectionsTotal = 150
    ConnectionsPerIP = 10
    SystemLogfile = /var/log/hiawatha/system.log
    GarbageLogfile = /var/log/hiawatha/garbage.log
    
    Binding {
    	Port = 80
    	Interface = 127.0.0.1
    }
    
    Binding {
    	BindingId = CGI
    	Port = 8080
    	Interface = 192.168.1.2xx
    	MaxRequestSize = 128
    	TimeForRequest = 3,20
    }
    
    
    Hostname = localhost
    WebsiteRoot = /root/Web-Server
    StartFile = index.html
    AccessLogfile = /var/log/hiawatha/access.log
    ErrorLogfile = /var/log/hiawatha/error.log
    
    MimetypeConfig = /etc/mime.types
    CGIhandler = /usr/bin/perl:pl,cgi
    CGIhandler = /usr/bin/php-cgi:php,html
    CGIextension = pl,bin,cgi
    ExecuteCGI = yes
    SecureURL = no
    
    FastCGIserver {
    	FastCGIid = PHP7
    	ConnectTo = /run/php/php-fpm.sock
    	Extension = php
    	SessionTimeout = 30
    }
    
    Virtualhost{
    	RequiredBinding = CGI
    	Hostname= 192.168.1.2xx
    	WebsiteRoot= /var/www/hiawatha
    	StartFile = index.php
    	showIndex = no
    	AccessLogfile = /var/log/hiawatha/access.log
    	ErrorLogfile = /var/log/hiawatha/error.log
    	UseFastCGI = PHP7
    	UseXSLT = yes
    
    	ExecuteCGI = yes
    	TimeForCGI = 10
    }
    
    
    /usr/bin/php-cgi というファイル(リンク)を作成するために ターミナルから 以下を実行
    # ln -s /usr/bin/php-cgi7.4 /usr/bin/php-cgi
    /run 配下に /php というディレクトリを作成し(/run/php)、そこに php7.4-fpm.sock という空のファイルを作成する。
    ここで以下を実行してみる。
    root# systemctl status php7.4-fpm.service
    	php7.4-fpm.service - The PHP 7.4 FastCGI Process Manager
    	Loaded: loaded (/lib/systemd/system/php7.4-fpm.service, disabled)
    	Active: inactive (dead)  #・・・または
    	Active: failed (failed)
    
    などとなって active にはならない。
    そこで BootManager で php7.4-fpm のチェックを外す。(OSを再起動する)
    www-data というユーザーを加える。
    root# adduser www-data
    passwd: /etc/shadow: bad record
    passwd: /etc/shadow: bad record
    passwd: /etc/shadow: bad record
    Changing password for www-data
    New password: 		#<-- ここにパスワード入力(www-data とか適当に)>
    Retype password: 
    passwd: password for www-data changed by root	
    ここでサービスを再起動するために、再度 以下を実行する。
    root# systemctl restart php7.4-fpm.service
    root# systemctl status php7.4-fpm.service
    php7.4-fpm.service - The PHP 7.4 FastCGI Process Manager
    	Loaded: loaded (/lib/systemd/system/php7.4-fpm.service, disabled)
    	Active: active (running)		#<-- active(running) となった -->
    となれば、hiawathaサーバー上で phpが実行されているので、例えば 以下のような test.html を作成し
    <!DOCTYPE html>
    <html>
    <head>
    	<title>PHP test</title>
    </head>
    <body>
    	<?php
    		echo "Congraturations! PHP script running!";
    	?>
     </body>
    </html>	
    http://localhost/test.html にアクセスして
    Congraturations! PHP script running!
    と表示されれば htmlファイル中で phpスクリプトが実行されていることが分かる。




  3. Perl cgiの動作確認
  4. ついでに、Perl スクリプトが実行されるか否かをチェックするために以下のスクリプトを記録した cgi_check.pl を /root/Web-Server ディレクトリに配置する。
    #!/usr/bin/perl -w
    
    print "Content-type: text/html\n\n";
    print '<meta charset="UTF-8">';
    print '<HTML><BODY bgcolor="dfdfff">';
    print "<h2>  Hello world</h2>";
    print "<b>\これが表示されたら  Perl は正常に実行されています</b><br>\n";
    print "<p style='color: blue;font-weight: bold;'> file path: /root/Web-Server/cgi_check.pl</p>";
    print "</BODY></HTML>";
    exit;
    
    その上で http://localhost/cgi_check.pl にアクセスして
    Hello world
    これが表示されたら Perl は正常に実行されています
    が表示されたら、Perl cgi が実行されている。


Access Counter:  総アクセス数