CentOSの7.xにphpMyAdminをインストールする方法についてです。
以前はファイルをアップロードしてインストールしていましたが、最近はyumで簡単にインストールすることができます。
バーチャルホストの設定と同じような簡単な設定で利用開始することができます。
PHPをremiでインストールしているので、phpMyAdminもremiでインストールします。
PHPのverは7.3なのでremi-php73と指定。
# yum install --enablerepo=remi-php73 phpMyAdmin
[設定ファイル(バーチャルホスト)]を開きます。
# cd /etc/httpd/conf.d/phpMyAdmin.conf
Apache2.4と2.2の設定があります。今回はApache2.4なので、2ヶ所修正しました。
ローカル環境での設定です。
<Directory /usr/share/phpMyAdmin/> AddDefaultCharset UTF-8 <IfModule mod_authz_core.c> # Apache 2.4 <RequireAny> #Require ip 127.0.0.1 #Require ip ::1 Require all granted </RequireAny> </IfModule> <IfModule !mod_authz_core.c> # Apache 2.2 Order Deny,Allow Deny from All Allow from 127.0.0.1 Allow from ::1 </IfModule> </Directory> <Directory /usr/share/phpMyAdmin/setup/> <IfModule mod_authz_core.c> # Apache 2.4 <RequireAny> #Require ip 127.0.0.1 #Require ip ::1 Require all granted </RequireAny> </IfModule> <IfModule !mod_authz_core.c> # Apache 2.2 Order Deny,Allow Deny from All Allow from 127.0.0.1 Allow from ::1 </IfModule> </Directory>
#Require ip 127.0.0.1
#Require ip ::1
の部分に#を付けてコメントアウト、そしてその下に
Require all granted
を記載します。
これで
http://xxx.xxx.xxx.xxx/phpmyadmin
にアクセスすると管理画面が表示されます。
表示されないときはSELinuxとfirewalldが効いている可能性があるので
# systemctl stop firewalld
# setenforce 0
を実行してみて下さい。
ディレクトリの変更
http://www.example.com/phpMyAdminでアクセスできるとセキュリティ的に良くないので、
# cd /etc/httpd/conf.d/phpMyAdmin.conf
を開き、
Alias /phpMyAdmin /usr/share/phpMyAdmin Alias /phpmyadmin /usr/share/phpMyAdmin
を変更します。
上記の2行を消して、下記のようにします。
Alias /sample /usr/share/phpMyAdmin
このようにすると http://www.example.com/sampleでphpMyAdminにアクセスできます。
phpMyAdminにログインできないときの対処法
ログインを試して、以下のエラーメッセージが出たときの対処法です。
mysqli::real_connect(): The server requested authentication method unknown to the client [caching_sha2_password] mysqli::real_connect(): (HY000/2054): The server requested authentication method unknown to the client
MySQL8からはパスワードの認証形式が変わっています。それによるエラーです。
古い認証形式に戻す場合は /etc/my.confを開いて下記を記述します。
[mysqld] default_authentication_plugin=mysql_native_password
既に作ってあるユーザーは個別に変更が必要です。
mysqlにログインして( mysql -u root -p )以下のコマンドを実行します。
> SELECT user, host, plugin FROM mysql.user;
pluginの欄にcaching_sha2_passwordと表示されているのが新しい認証方式です。
古い認証方式はmysql_native_passwordになります。
個別に変更するにはmysqlのターミナルから下記を実行します。
ALTER USER 'root'@'localhost' identified WITH mysql_native_password BY 'パスワード';
Basic認証
Basic認証を行いたいときは、 </Directory>内に下記を記載します。
Basic認証用のID/PASSの書かれたファイルは別の場所に配置します。
<Files ~ "^\.(htaccess|htpasswd)$"> deny from all </Files> AuthUserFile /パスワードファイル・ディレクトリ/.htpasswd AuthGroupFile /dev/null AuthName "Please enter your ID and password" AuthType Basic require valid-user order deny,allow