Raspberry Pi jessie Nginx+php-fpm webサーバー
Raspberry PiでNginxをセットアップする方法はwww.raspberrypi.orgに文書があるのですがwheezyの頃と思いますので現行のjessieと若干違うところがあります。
日本語訳サイト ラズベリーパイ上でNGINXサーバをセットアップする
今回はこの文書に添ってphp-fpmの動作まで確認したいと思います。
aptでインストール
aptでインストールできるパッケージはいくつかあるようです。
raspbianでは以下の3つがあります。
nginx-light – nginx web/proxy server (basic version)
nginx-full – nginx web/proxy server (standard version)
nginx-extras – nginx web/proxy server (extended version)
特に指定しなければnginx-full(standard version)がインストールされます。
# apt install nginx
インストールが終わるとデーモンは自動で起動されます。
% systemctl status nginx.service ● nginx.service - LSB: Stop/start nginx Loaded: loaded (/etc/init.d/nginx) Active: active (running) since
webサーバーをテスト
インストールしたサーバーのIPアドレスを指定してデフォルトのWEBページを開いてみます。
次のようなページが表示されるはずです。
デフォルトのWEBページを変更する
nginxのWEBページはRaspbianではデフォルトで/var/www/htmlに置かれています。
index.nginx-debian.html
php5-fpmインストール
# apt install php5-fpm
インストールが終わるとデーモンは自動で起動されます。
% systemctl status php5-fpm.service ● php5-fpm.service - The PHP FastCGI Process Manager Loaded: loaded (/lib/systemd/system/php5-fpm.service; enabled) Active: active (running) since
nginxでphpを有効にする
/etc/nginx/sites-available/defaultの編集
indexの項にindex.phpを追記。
PHPの設定は4箇所のコメントアウトを外します。
# Add index.php to the list if you are using PHP index index.php index.html index.htm index.nginx-debian.html; # 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; }
編集が終わったらnginxを再起動します。
# systemctl restart nginx.service
phpをテスト
/var/www/htmlに次の内容をphpinfo.phpとして作成します。
# vi /var/www/html/phpinfo.php <?php phpinfo(); ?>
サーバーのIPアドレス/phpinfo.phpを指定してWEBページを開いてみます。
次のようなページが表示されるはずです。