LoginSignup
2
4

More than 1 year has passed since last update.

Raspberry Pi で Apache2 を動かす

Last updated at Posted at 2020-06-15

Raspberry Pi で Apache2 を動かします。

次の PHP と Perl が動くようにします。

test_a001.php
<?php
        foreach ($_SERVER as $key => $val)
                {
                echo $key . ' : ' . $val . '<br />';
                }
?>
hello.pl
#! /usr/bin/perl
#
print "Content-type: text/html\n\n";
print "<html>\n";
print "<head>\n";
print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n";
print "<title>Hello by Perl</title>\n";
print "</head>\n";
print "<body>\n";
print "Hello<p />\n";
print "こんにちは<p />\n";
print "Jun/16/2020<p />\n";
print "</body>\n";
print "</html>\n";

Apache2 のインストール

sudo apt install apache2

インストールしただけで起動します。
状態の確認

sudo systemctl status apache2

ブラウザーでアクセスすると、
 /var/www/html/index.html が表示されます。
apache2_jun16.png

PHP をインストール

sudo apt install php php-cli php-curl

PHP のバージョンの確認

$ php --version
PHP 7.3.27-1~deb10u1 (cli) (built: Feb 13 2021 16:31:40) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.27, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.3.27-1~deb10u1, Copyright (c) 1999-2018, by Zend Technologies

ブラウザーでアクセスすれば、次のように表示されます。
php_jun1602.png

Perl の設定
バージョンの確認

$ perl --version

This is perl 5, version 28, subversion 1 (v5.28.1) built for arm-linux-gnueabihf-thread-multi-64int
(with 61 registered patches, see perl -V for more detail)

Copyright 1987-2018, 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 http://www.perl.org/, the Perl Home Page.

CGI を有効にする

sudo a2enmod cgid
sudo systemctl restart apache2

/etc/apache2/apache2.conf に次を加える

/etc/apache2/apache2.conf
(省略)
AddHandler cgi-script .cgi .pl

ページにアクセスすると、

Forbidden

You don't have permission to access this resource.
Apache/2.4.38 (Raspbian) Server at tulip.local Port 80

/etc/apache2/apache2.conf の設定の変更

/etc/apache2/apache2.conf
<Directory /var/www/>
        Options Indexes FollowSymLinks ExecCGI
        AllowOverride None
        Require all granted
</Directory>

ブラウザーからアクセス
perl_jun16.png

次のバージョンで確認しました。

$ uname -a
Linux violet 5.10.17-v7l+ #1414 SMP Fri Apr 30 13:20:47 BST 2021 armv7l GNU/Linux
2
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
4