MariaDB and phpMyAdmin on MacOSX

開発環境(Mac)にnginx + unicorn入れたので、DBもMariaDBにしてみます。

ネコでもわかる!さくらのVPS講座 ~第四回「phpとMariaDBをインストールしよう」」と「ネコでもわかる!さくらのVPS講座 ~第五回「phpMyAdminを導入しよう」」でやったのと同じことをします。

MariaDBのインストール

$ brew install mariadb

とすると、コンフリクトが起こってるということで、インストールする前にbrew unlink mysqlしろと言われました。mysqlが入っていたのか入れていたのか、どっちかは分からないですが、言われたとおりにします。

$ brew unlink mysql
$ brew install mariadb

mysqlの起動と初期設定

$ mysql.server start
$ mysql_secure_installation

Enter current password for root (enter for none): (何も入力せずEnter)

Set root password? [Y/n] Y

New password:
Re-enter new password:

ERROR 1054 (42S22) at line 1: Unknown column 'Password' in 'field list'

と、なぜかエラーが。

MySQL 5.7.6でroot用パスワードが変わらなくて困った話

MySQL 5.7.6でmysql.userテーブルのパスワードのカラム名がなんか変わった

によると、passwordがauthentication_stringに変更になってるとのこと。

とりあえず、パスワードは後で設定するとして、mysql_secure_installationの続きをやっちゃいます。

$ mysql_secure_installation

Enter current password for root (enter for none): (何も入力せずEnter)

Set 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

rootのパスワードを設定します。

$ mysql -u root mysql

> update user set authentication_string=password("********") where user='root';
> flush privileges;
> quit;

$ mysql.server stop
$ mysql.server start

これでうまくいったはずです。ログインしてみます。

$ mysql -u root -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 13
Server version: 10.2.14-MariaDB Homebrew

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>

うまくいった。ほっ。

php.iniの設定

php.iniにmysqlのソケットの登録をしておきます。

まずはソケットの確認をします。

$ mysql_config --socket
/tmp/mysql.sock

私の環境では、/tmp/mysql.sockが表示されましたので、このパスをphp.iniに登録します。

ちなみに、php.iniの場所は、

$ php -i | grep php.ini

で確認できます。

$vi php.ini

・・・
pdo_mysql.default_socket=/tmp/mysql.sock
・・・
mysqli.default_socket=/tmp/mysql.sock
・・・

pdo_mysql.default_socketとmysqli.default/socketに記載しておきます。(2つとも必要かは不明。)

設定したら再起動します。

$ brew services restart php

私の環境では$brew install phpでいれたphpのバージョンは7.2.5で、php-fpmは別途入れなくても入っているような気がする。

$ brew services start php
$ lsof -Pni | grep LISTEN | grep php

とすれば、php-fpmが動いているのが確認できる。

phpMyAdminをインストール

phpMyAdminをインストールしておきます。

composerでインストールできるみたいです。

$ composer create-project phpmyadmin/phpmyadmin

nginx用のphpmyadmin.confを作成します。

$ vi /usr/local/etc/nginx/servers/phpmyadmin.conf

server {

	listen 8083;
	server_name localhost;
	root /Users/ky/phpmyadmin;

	access_log /usr/local/var/log/nginx/phpmyadmin_access.log;
	error_log  /usr/local/var/log/nginx/phpmyadmin_error.log;

	location / {
        try_files $uri $uri/index.php?$query_string /index.php?$query_string; 
    }

	location ~ \.php$ {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root/$fastcgi_script_name;
        include        fastcgi_params;
    }

}

これで、nginxを再起動してからlocalhost:8083にアクセスすれば、phpMyAdminにアクセスできます。

ログインすると画面の下に「設定ファイルに、暗号化 (blowfish_secret) 用の非公開パスフレーズの設定を必要とするようになりました。」と表示されていますので、config.inc.phpにパスフレーズを記載します。

$ cp config.sample.inc.php config.inc.php
$ vi config.inc.php

・・・
$cfg['blowfish_secret'] = ''; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */
・・・

$cfg[‘blowfish_secret’]の部分に、32文字以上の任意の文字列を記載しておきます。パスワードの生成は、http://www.luft.co.jp/cgi/randam.phpとかが便利です。

設定後、再ログインすると表示が消えています。

2 COMMENTS

現在コメントは受け付けておりません。