0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

ラズベリーパイで小型Webサーバーをつくってみる。(その2)

Posted at

前回はラズベリーパイにnginxをインストールして、ブラウザ上で静的なページを表示しました。
今回はphpをインストールして動的なページを表示してみます。

PHPをインストール

sudo apt install php7.3-fpm

nginx上での設定

PHPをインストールしたら次はnginx上でPHPを利用するための設定をします。
/etc/nginx/sites-available/defaultを編集します。

sudo mousepad /etc/nginx/sites-available/default

エディタを開いたら、「#ADD index.php to the list if you are uging index.php」と書かれた場所を探し、index.phpを追加します。
スクリーンショット 2022-02-26 20.51.42.png

次に、「location」と書かれた場所を探し、}までの#を削除して下の画像のようにします。
fastcgi_pass 127.0.0.1:9000;と書かれた部分の#は削除しないので注意してください。
スクリーンショット 2022-02-26 20.56.34.png

完了したら保存して、次は「/etc/php/7.3/fpm/php.ini」を編集します。

sudo mousepad /etc/php/7.3/fpm/php.ini

control + Fで「cgi.fix_pathhinfo」と検索し、「cgi.fix_pathhinfo = 1」を「cgi.fix_pathhinfo = 0」に変更します。
スクリーンショット 2022-02-26 21.01.04.png

変更したら保存して、phpとnginxを再起動します。

sudo systemctl restart php7.3-fpm
sudo systemctl restart nginx

最後に/var/www/html/にてphpファイルを作成してみます。

sudo mousepad /var/www/html/test.php

現在時刻を表示してみましょう。

<?php
echo date("Y/m/d H:i:s");
?>

ブラウザで/test.phpにアクセスすると現在時刻が表示されました!
http://ラズベリーパイのIPアドレス/test.php
スクリーンショット 2022-02-26 21.49.14.png

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?