Berikut langkah-langkah instalasi PhpMyAdmin pada Ubuntu 20.04. Sebelum melakukan instalasi PhpMyAdmin, anda sudah harus menginstall LEMP stack (Linux Engin-X MySQL PHP) di mesin anda.

Selanjutnya, lakukan instalasi PHP extension yang diperlukan:

sudo apt install -y php-json php-mbstring

Kemudian install PhpMyAdmin. Karena package PhpMyAdmin yang ada pada repository Ubuntu cukup tua, maka kita akan mendownload versi terbaru PhpMyAdmin dari website officialnya. Anda bisa melihatnya di artikel Cara Instalasi LEMP ini.

wget https://files.phpmyadmin.net/phpmyadmin/5.0.2/phpmyadmin-5.0.2-all-languages.tar.gz
tar -zxvf phpmyadmin-5.0.2-all-languages.tar.gz
sudo mv phpmyadmin-5.0.2-all-languages /usr/share/phpmyadmin

Kemudian copy file configurasi dari sample yang ada:

sudo cp -pr /usr/share/phpMyAdmin/config.sample.inc.php /usr/share/phpMyAdmin/config.inc.php

Lalu edit konfigurasinya:

sudo nano /usr/share/phpMyAdmin/config.inc.php

Generate blowfish secret code dan salin ke konfigurasi:

$cfg['blowfish_secret'] = 'CfX1la/aG83gx1{7rADus,iqz8RzeV8x';

Uncomment dan modifikasi konfigurasi seperti berikut:

/**
 * phpMyAdmin configuration storage settings.
 */

/* User used to manipulate with storage */
$cfg['Servers'][$i]['controlhost'] = 'localhost';
// $cfg['Servers'][$i]['controlport'] = '';
$cfg['Servers'][$i]['controluser'] = 'pma';
$cfg['Servers'][$i]['controlpass'] = 'pmapass';

/* Storage database and tables */
$cfg['Servers'][$i]['pmadb'] = 'phpmyadmin';

Import create_tables.sql:

sudo mysql < /usr/share/phpMyAdmin/sql/create_tables.sql -u root -p

Login ke MySQL:

sudo mysql -u root -p

Tambahkan user:

CREATE USER 'pma'@'localhost' IDENTIFIED BY 'pmapass';
GRANT ALL ON phpmyadmin.* TO 'pma'@'localhost';
FLUSH PRIVILEGES;
exit

Buat virtualhost di Nginx:

sudo nano /etc/nginx/conf.d/phpmyadmin.conf

Ganti server_name sesuai dengan konfigurasi mesin anda:

server {
  listen 80;
  server_name pma.local;
  root /usr/share/phpmyadmin;

  location / {
    index index.php;
  }

  ## Images and static content is treated different
  location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|xml)$ {
    access_log off;
    expires 30d;
  }

  location ~ /\.ht {
    deny all;
  }

  location ~ /(libraries|setup/frames|setup/libs) {
    deny all;
    return 404;
  }

  location ~ \.php$ {
    include /etc/nginx/fastcgi_params;
    # fastcgi_pass 127.0.0.1:9000;
    fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  }
}

Kemudian buat direktori tmp:

sudo mkdir /usr/share/phpmyadmin/tmp
sudo chmod 777 /usr/share/phpmyadmin/tmp
sudo chown -R www-data:www-data /usr/share/phpmyadmin

Lalu restart service:

sudo systemctl restart nginx
sudo systemctl restart php7.4-fpm

Kemudian create dbadmin user:

GRANT ALL PRIVILEGES ON *.* TO 'dbadmin'@'localhost' IDENTIFIED BY 'password';
FLUSH PRIVILEGES;
EXIT;

Kemudian coba akses PhpMyAdmin dari browser: