さくらVPS【CentOS8】phpMyAdmin

さくらVPSでカスタムインストールしたCentOS8にphpMyAdminをインストール

さくらVPS【CentOS8】PHP」でPHP7.2をインストールしたCentOS8(以下、CentOS8Server)にphpMyAdminをインストールしました。

◎phpMyAdmin用のユーザーの作成

  • su コマンドでrootになって、phpMyAdmin用のユーザー(phpmyadmin)を作成しました。
    $ su -
    パスワード:
    # adduser phpmyadmin
    # passwd phpmyadmin
    Changing password for user phpmyadmin.
    New password: 
    Retype new password: 
    passwd: all authentication tokens updated successfully.
    #
    

◎phpMyAdminのインストール

  • suコマンドで、phpMyAdmin用のユーザー(phpmyadmin)になり、ホームディレクトリに移動しました。

    # su phpmyadmin
    $ cd ~
    $ pwd
    /home/phpmyadmin
    $
    
  • ユーザー(phpmyadmin)のホームディレクトリでwgetコマンドを使用して、phpMyAdminのソースファイル(phpMyAdmin-4.9.1-all-languages.zip)をダウンロードしました。

    $ wget https://files.phpmyadmin.net/phpMyAdmin/4.9.1/phpMyAdmin-4.9.1-all-languages.zip
    $ ls
    phpMyAdmin-4.9.1-all-languages.zip
    $
    
  • ダウンロードしたphpMyAdminのソースファイル(phpMyAdmin-4.9.1-all-languages.zip)を解凍し、解凍して出来たフォルダの名前を「public_html」に変更しました。

    $ unzip phpMyAdmin-4.9.1-all-languages.zip
    $ mv phpMyAdmin-4.9.1-all-languages public_html
    $ (rm phpMyAdmin-4.9.1-all-languages.zip)
    $
    
  • 「public_html」に移動し、「config.sample.inc.php」をコピーして「config.inc.php」を作成しました。

    $ cd public_html
    $ cp config.sample.inc.php config.inc.php
    $
    
  • エディタ(nano)で「config.inc.php」を編集しました。
    $ nano config.inc.php
    $
    
    • $cfg[‘blowfish_secret’] に適当な語句を設定しました。($cfg[‘blowfish_secret’]の文字列の長さが短すぎると後で怒られます。)
      $cfg['blowfish_secret'] = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'; 
      
    • ルートパスワード(root_password)でphpMyAdminにログインできるようにするために以下の設定を追記しました。
      /* Authentication type */
      /* $cfg['Servers'][$i]['auth_type'] = 'cookie'; */
      $cfg['Servers'][$i]['auth_type'] = 'config';
      $cfg['Servers'][$i]['user'] = 'root';
      $cfg['Servers'][$i]['password'] = 'root_password';
      
  • 「./tmp」ディレクトリがなかったので作成し、パーミションを「777」に変更しました。
    $ pwd
    /home/phpmyadmin/public_html
    $ mkdir ./tmp
    $ chmod 777 ./tmp/
    $
    

◎Apacheの設定

  • /etc/httpd/conf.d/userdir.confを修正して、ユーザーのホームページが公開できるようにしました。

    $ su -
    Password:
    # cd /etc/httpd/conf.d/
    # cp userdir.conf userdir.conf.org
    # nano userdir.conf
    #
    
    • 修正内容は、以下の内容です。

      #-#UserDir disabled
      UserDir enable
      #-#UserDir public_html
      UserDir public_html
      
  • /home/phpmyadmin/public_html/の権限を変更しました。

    # chmod g+x /home/phpmyadmin/
    # chown :apache /home/phpmyadmin/
    #
    
  • systemctlコマンドでhttpdサービスを再起動しました。
    # systemctl restart httpd
    #
    

Basic認証

  • phpMyAdminのホームページ「http://(CentOS8ServerのURL)/~phpmyadmin/」でBasic認証を行うために、「/var/www」フォルダ以下にユーザー名:「phpmyadmin」(任意)で「.htpasswd」を作成しました。
    # cd /var/www
    # htpasswd -c /var/www/.htpasswd phpmyadmin
    New password: 
    Re-type new password: 
    Adding password for user phpmyadmin
    #
    
  • 続いて、「/home/phpmyadmin/public_html」フォルダに「.htaccess」を作成しました。
    # cd /home/phpmyadmin/public_html
    # nano .htaccess
    #
    
    • 「.htaccess」の内容は下記のように記載しました。
      AuthType Basic
      	AuthUserFile /var/www/.htpasswd
      	AuthName "Please enter your name and password."
      	Require valid-user
      
  • systemctlコマンドでhttpdサービスを再起動しました。
    # systemctl restart httpd
    #
    
  • phpMyAdminのホームページ「http://(CentOS8ServerのURL)/~phpmyadmin/」にアクセスすると認証ダイアログがポップアップ表示されたので、設定したユーザー名とパスワードで認証が出来て、phpMyAdminにログインできることを確認して、phpMyAdminのインストールを完了しました。
<= さくらVPS【CentOS8】PHP | | さくらVPS【CentOS8】HTTPS化 =>
スポンサーリンク
ohhappyをフォローする
Sakura.Oh!Happy.JP