Raspberry Pi に nginx と PHP をインストール

環境:Raspberry Pi 3 Model B、Jessie

nginx のインストールは簡単だった。

(1)nginx のインストール。

$ sudo apt-get install nginx

(2)nginx を起動。

$ sudo /etc/init.d/nginx start

Raspberry Pi の IP アドレスにアクセスすればテストページが表示されるはず。

参考:
Raspberry Pi にWebサーバ入れてphp動かす – Qiita
https://qiita.com/Brutus/items/27525deedb0eea1b35b8

PHP のインストールには手こずった。PHP 7 をインストールしようとするとエラーが出て進めない。仕方がないので PHP 5 をインストールした。

(1)PHP 5 のインストール。

$ sudo apt-get install php5-fpm

PHP のバージョンチェック。

$ php -v

(2)nginx で PHP を使う設定。

$ sudo nano /etc/nginx/sites-available/default

(3)# Add index.php to the list if you are using PHP に index.php を追加。

index index.html index.htm index.nginx-debian.html index.php;

(4)以下のようにコメントアウトを外す。

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
                include snippets/fastcgi-php.conf;

        #       # With php5-cgi alone:
        #       fastcgi_pass 127.0.0.1:9000;
        #       # With php5-fpm:
                fastcgi_pass unix:/var/run/php5-fpm.sock;
        }

(5)nginix の再起動。

$ sudo systemctl restart nginx.service

(6)テストページの作成。

$ sudo nano /var/www/html/phpinfo.php

以下を記入、保存。

<?php
phpinfo();
?>

(7)以下のページにアクセスしてテストページが表示されれば完了。

http://[Raspberry Pi の IP アドレス]/phpinfo.php

サイト用のファイルは /var/www/html 以下に置けばいい。

参考:
Raspberry Pi jessie Nginx+php-fpm webサーバー
https://dbpro.xyz/1862