LoginSignup
21
31

More than 3 years have passed since last update.

MariaDB・phpMyAdminのインストールと設定

Last updated at Posted at 2018-07-12

今回はMariaDBとphpMyAdminをインストールして設定します。

前回同様の環境です。
〜さくらのVPS 1Gプラン〜
メモリ:1G
CPU:仮想2Core
ストレージ:HDD 100GB
OS:CentOS 7(カスタムOS)

仮として、アカウント名はrootもしくはabc123、ドメインはabc.comとします。

はじめに

Terminalでログインできていることを前提とする。

[root@abc ~]# 

1.MariaDBをインストールする

次のコマンドを実行し、MariaDBをインストールする。

[root@abc ~]# yum -y install mariadb-server
読み込んだプラグイン:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: ftp.iij.ad.jp
 * epel: ftp.jaist.ac.jp
 * extras: ftp.iij.ad.jp
 * remi-safe: ftp.riken.jp

〜〜省略〜〜

インストール:
  mariadb-server.x86_64 1:5.5.56-2.el7                                          

依存性関連をインストールしました:
  mariadb.x86_64 1:5.5.56-2.el7       perl-DBD-MySQL.x86_64 0:4.023-6.el7      

完了しました!

次のコマンドを実行し、MariaDBを起動する。

[root@abc ~]# systemctl start mariadb

次のコマンドを実行し、OS起動時、自動でMariaDBも起動するようにする。

[root@abc ~]# systemctl enable mariadb

2.MariaDBをセットアップする

次のコマンドを実行し、ログインするためのパスワードを設定する。

[root@abc ~]# mysql_secure_installation

すると次のようなものが表示される。
デフォルトではパスワードが未設定のため、何も入力せずreturnキーを押す。

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): 

パスワードを設定するか聞かれる。

OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] 

"Y"を入力し、returnキーを押し、設定したいパスワードを入力し、returnキーを押す。

Set root password? [Y/n] Y
New password:

すると次のようなものが表示される。

Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] 

"Y"を入力し、returnキーを押す。

Remove anonymous users? [Y/n] Y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] 

同じく"Y"を入力し、returnキーを押す。

Disallow root login remotely? [Y/n] Y
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] 

同じく"Y"を入力し、returnキーを押す。

Remove test database and access to it? [Y/n] Y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] 

同じく"Y"を入力し、returnキーを押す。

Reload privilege tables now? [Y/n] Y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!
[root@abc ~]# 

3.phpMyAdminをインストールする

次のコマンドを実行し、phpMyAdminをインストールする。

[root@abc ~]# yum -y install --enablerepo=remi,remi-php73 phpMyAdmin
読み込んだプラグイン:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: ftp.iij.ad.jp
 * epel: ftp.jaist.ac.jp
 * extras: ftp.iij.ad.jp
 * remi: ftp.riken.jp
 * remi-php73: ftp.riken.jp
 * remi-safe: ftp.riken.jp
 * updates: ftp.iij.ad.jp

〜〜省略〜〜

  php-symfony3-translation.noarch 0:3.4.12-1.el7.remi                           
  php-twig.noarch 0:1.35.3-1.el7.remi.7.3                                       
  php-twig-extensions.noarch 0:1.5.1-1.el7.remi                                 
  php-xml.x86_64 0:7.1.19-1.el7.remi                                            
  recode.x86_64 0:3.6-38.el7                                                    

完了しました!
[root@abc ~]# 

4.phpMyAdminをセットアップする

次のコマンドを実行し、phpMyAdminの設定ファイルを開く。

[root@abc ~]# vim /etc/httpd/conf.d/phpMyAdmin.conf

第三者にphpMyAdminのURLを推測されにくくするため、8行目の"phpMyAdmin"、9行目の"phpmyadmin"それぞれの後ろに適当な文字列をつける。

/etc/httpd/conf.d/phpMyAdmin.conf
Alias /phpMyAdmin /usr/share/phpMyAdmin
Alias /phpmyadmin /usr/share/phpMyAdmin

/etc/httpd/conf.d/phpMyAdmin.conf
Alias /phpMyAdmin2ekS8nA /usr/share/phpMyAdmin
Alias /phpmyadmin2ekS8nA /usr/share/phpMyAdmin

SSL通信のみ許可するため、空いている13行目に"SSLRequireSSL"を入力する。

/etc/httpd/conf.d/phpMyAdmin.conf
<Directory /usr/share/phpMyAdmin/>
   AddDefaultCharset UTF-8

   Require local

/etc/httpd/conf.d/phpMyAdmin.conf
<Directory /usr/share/phpMyAdmin/>
   AddDefaultCharset UTF-8
   SSLRequireSSL
   Require local

どこからでもアクセスできるようにするため、14行目の"Require local"を"Require all granted"にする。

/etc/httpd/conf.d/phpMyAdmin.conf
     SSLRequireSSL
     Require local
  </Directory>

/etc/httpd/conf.d/phpMyAdmin.conf
     SSLRequireSSL
     Require all granted
  </Directory>

次のコマンドを実行し、mod_sslをインストールする。

[root@abc ~]# yum -y install mod_ssl

設定を反映させるため、Apacheを再起動する。

[root@abc ~]# systemctl restart httpd

ブラウザでhttps://"ご自身のIPアドレス"/phpMyAdmin"設定した文字列"にアクセスする。
SSL証明書がないためエラーメッセージが表示されるが、許可する操作をしてアクセスできることを確認する。
この時点ではrootユーザしかないため、ユーザ名はroot、パスワードは上の2で設定したものを入力し、ログインする。
もしもログインできなかったり、403エラーなどが表示されたら最初からやり直す。

21
31
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
21
31