LoginSignup
3
3

More than 5 years have passed since last update.

ラズパイにローカルWeb開発環境構築

Posted at

はじめに

いろいろ触りたいのでまずは環境構築しようと思います。
ということで、Raspberry pi3(Raspbian)上にNginxの環境構築をします。

環境

-OS X 10.11.1
-Nginx 1.10.3
-PHP 7.0.27-0+deb9u1

Nginxのインストールと設定

コマンドラインからNginxをインストールします。

インストール
$ sudo apt-get install nginx

起動確認します。下記コマンドでActiveとなっていればOK

状態確認
$ service nginx status
(中略)
Active: active (running) since Thu 2018-04-05 21:33:42 JST

起動してなければ下記コマンドで。

起動
$ service nginx start

接続テストをするためにMac上でWebブラウザを開いてラズベリーパイのIPアドレスを入力します。
IPを調べる場合はラズパイ上で下記のようにコマンドラインに入力すればOKです

$ hostname -I

この画面が開けばOK
スクリーンショット 2018-04-05 21.41.43.png

PHPのインストールと設定

PHP7.0と併せてPHPのMySQL接続モジュールをインストールします。
(のちのちMySQLをインストールしたいため)

& sudo apt install php7.0 php7.0-fpm php7.0-mysql

NginxでPHPを使うための設定

設定ファイルを修正します。

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

下記の箇所にindex.phpを追加。

43行目
# Add index.php to the list if you are using PHP
        index index.html index.htm index.nginx-debian.html index.php;

下記の箇所のコメントを外します。
最後の"}"を忘れるとNginxが起動しなくなるので気をつけましょう(ダサいけどハマりました)
location ~ .php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
}

全体としてはこんな感じ

54行目〜
# pass PHP scripts to FastCGI server
        #
        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
        #
        #       # With php-fpm (or other unix sockets):
                fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
        #       # With php-cgi (or other tcp sockets):
        #       fastcgi_pass 127.0.0.1:9000;
        }

実験

/var/www/html配下にindex.phpを置きます。

<?php
 phpinfo();
?>

PHPのバージョン等々が表示されます。
スクリーンショット 2018-04-06 21.37.40.png

感想

構築自体は簡単。ちゃんと使いこなすにはconfの内容とか諸々理解しないと駄目なんでしょうが、ひとまずこの環境を使っていろいろ遊んでいきたいと思います。

参考URL

下記の記事を参考にさせていただきました、ありがとうございます!
ラズベリーパイ上でNGINXサーバをセットアップする
Raspberrypi2をNginxでWebサーバ化
Nginx PHP7 絶対にできる設定
Nginx導入時やること

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