fc2ブログ

ぽよメモ

NginxにphpMyAdminを通す


Nginxの最新版の導入が成功しましたら、データベースをより管理しやすくするためにphpMyAdminを入れます。
(インストールはこの前の記事でやった)
まずはphp5の環境設定から。
$ sudo vim /etc/php5/fpm/php.ini

・683行目付近 文字コードの設定
default_charset = "UTF-8"

・865行目付近 タイムゾーンの設定
date.timezone = "Asia/Tokyo"

・1645行目付近 言語設定
mbstring.language = Japanese


$ sudo vim /etc/php5/fpm/pool.d/www.conf

・22行目付近 PHP実行ユーザ名の設定
user = nginx

・23行目付近 PHP実行グループ名の設定
group = nginx

・33行目付近 FastCGIリクエストの設定
listen = 127.0.0.1:9000
ここまできたらサービスの再起動を行います。
sudo /etc/init.d/php5-fpm restart


MySQLのセキュリティのための設定
$ mysql_secure_installation

Enter current password for root (enter for none):  ←パッケージ導入時に指定したパスワードを入力
Change the root password? [Y/n] n
Remove anonymous users? [Y/n] y
Disallow root login remotely? [Y/n] y
Remove test database and access to it? [Y/n] y
Reload privilege tables now? [Y/n] y
Thanks for using MySQL!


ここからはNginxの設定に入ります。

公開ドメイン名: www.poyo.info
ドキュメントルート: /var/www
Wordpress: /var/www/wordpress
phpMyAdmin: /usr/share/phpmyadmin

としておきます。
$ sudo vim /etc/nginx/nginx.conf

user nginx;
worker_processes 4; # Raspberry Pi2なので「1」→「4」に修正

error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;


events {
worker_connections 1024;
}


http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

access_log /var/log/nginx/access.log main;

sendfile on;
#tcp_nopush on;

keepalive_timeout 65;

gzip on; #コメントアウトを外す Gzip圧縮転送を有効
include /etc/nginx/conf.d/*.conf;
}
Nginxは/etc/nginxにインストールされているはずです。
各種設定は/etc/nginx/conf.d/*.confとして保存し、先ほどのnginx.confによってincludeされます。
まずはデフォルトで入っている設定ファイル類のバックアップを取ります。
$ cp /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/wordpress.conf
$ mv /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf.org
$ cp /usr/share/nginx/html/index.html /var/www/index.html
$ cp /usr/share/nginx/html/50x.html /var/www/50x.html

次にWordpressとphpMyAdminの設定をかきます。
$ sudo vim /etc/nginx/conf.d/wordpress.conf

server {
listen 80;
server_name poyo.info www.poyo.info;

# アップロードできるサイズの指定(Nginxのデフォルト値は1MByte)
client_max_body_size 16M;

# www が省略時されたときでも、www を付加したサーバ名に統一する
if ($http_host = "poyo.info") {
rewrite (.*) http://www.poyo.info$1;
}

location / {
root /var/www;
index index.php index.html index.htm;
}
 location /blog {
alias /var/www/wordpress;
index index.php;
# WordPress用のファイル・ディレクトリ不在時のリダイレクト対応
try_files $uri $uri/ /wordpress/index.php?$args;
# WordPress用のカスタムパーマリンク対応
if (!-e $request_filename) {
rewrite ^.+?($/.*) $1 last;
rewrite ^.+?(/.*\.php)$ $1 last;
rewrite ^ /wordpress/index.php last;
}
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/www;
}
# FastCGI用の設定
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www$fastcgi_script_name;
include fastcgi_params;
}
location /phpmyadmin {
alias /usr/share/phpmyadmin;
index index.php
#アクセスの制限
allow 127.0.0.1;
allow 192.168.0.0/24;
deny all;
}
location ~ /phpmyadmin/.*\.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/$uri;
include fastcgi_params;
}
}
これでhttp://[ラズパイのIPアドレス]/phpmyadminにアクセスすればphpMyAdminが表示されるはずです。


スポンサーサイト



カテゴリー:RaspberryPi


コメントの投稿はこちらから ♥

COMMENT-FORM

SECRET