sudo apt install -y php-json php-mbstring

Install phpMyAdmin

phpMyAdmin package is not yet available in Debian repository for Debian 10. So, we need to download the tar package from the official website.

wget https://files.phpmyadmin.net/phpMyAdmin/4.9.0.1/phpMyAdmin-4.9.0.1-all-languages.tar.gz

Extract the phpMyAdmin tarball using the following command.

tar -zxvf phpMyAdmin-4.9.0.1-all-languages.tar.gz

Move the phpMyAdmin set up to the desired location.

sudo mv phpMyAdmin-4.9.0.1-all-languages /usr/share/phpmyadmin

Configure phpMyAdmin

Copy the sample configuration file.

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

Edit the configuration file and add a blowfish secret.

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

Generate blowfish secret and then place it into the below line.

$cfg['blowfish_secret'] = '2O:.uw6-8;Oi9R=3W{tO;/QtZ]4OG:T:'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */

Also, uncomment the phpMyAdmin storage settings shown like below.

/**
 * 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';
$cfg['Servers'][$i]['bookmarktable'] = 'pma__bookmark';
$cfg['Servers'][$i]['relation'] = 'pma__relation';
$cfg['Servers'][$i]['table_info'] = 'pma__table_info';
$cfg['Servers'][$i]['table_coords'] = 'pma__table_coords';
$cfg['Servers'][$i]['pdf_pages'] = 'pma__pdf_pages';
$cfg['Servers'][$i]['column_info'] = 'pma__column_info';
$cfg['Servers'][$i]['history'] = 'pma__history';
$cfg['Servers'][$i]['table_uiprefs'] = 'pma__table_uiprefs';
$cfg['Servers'][$i]['tracking'] = 'pma__tracking';
$cfg['Servers'][$i]['userconfig'] = 'pma__userconfig';
$cfg['Servers'][$i]['recent'] = 'pma__recent';
$cfg['Servers'][$i]['favorite'] = 'pma__favorite';
$cfg['Servers'][$i]['users'] = 'pma__users';
$cfg['Servers'][$i]['usergroups'] = 'pma__usergroups';
$cfg['Servers'][$i]['navigationhiding'] = 'pma__navigationhiding';
$cfg['Servers'][$i]['savedsearches'] = 'pma__savedsearches';
$cfg['Servers'][$i]['central_columns'] = 'pma__central_columns';
$cfg['Servers'][$i]['designer_settings'] = 'pma__designer_settings';
$cfg['Servers'][$i]['export_templates'] = 'pma__export_templates';

Credit: TECHIES WORLD

Import the create_tables.sql to create tables for phpMyAdmin.

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

Login to MariaDB.

sudo mysql -u root -p

Add the user and grant permission to phpMyAdmin’s database.

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

FLUSH PRIVILEGES;

Create an alias in Apache web server to access phpMyAdmin with http://your-ip-add-dress/phpmyadmin.

sudo nano /etc/apache2/sites-available/phpmyadmin.conf

Copy and paste the below content into the above file.

Alias /phpMyAdmin /usr/share/phpmyadmin
Alias /phpmyadmin /usr/share/phpmyadmin

<Directory /usr/share/phpMyAdmin/>
   AddDefaultCharset UTF-8

   <IfModule mod_authz_core.c>
     # Apache 2.4
     <RequireAny> 
      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 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>

Enable the virtual host with the below command.

sudo a2ensite phpmyadmin

Create the tmp directory for phpMyAdmin and change the permission.

sudo mkdir /usr/share/phpmyadmin/tmp

sudo chmod 777 /usr/share/phpmyadmin/tmp

Set the ownership of phpMyAdmin directory.

sudo chown -R www-data:www-data /usr/share/phpmyadmin

Restart the Apache web service.

sudo systemctl restart apache2

Create DB & User

By default, MariaDB root user is allowed to log in locally via Unix socket. So, we will now create a database user and login to phpMyAdmin with that user.

CREATE DATABASE app_db;

GRANT ALL PRIVILEGES ON app_db.* TO 'app_user'@'localhost' IDENTIFIED BY 'password';

FLUSH PRIVILEGES;

EXIT;

Access phpMyAdmin

Now, access the phpMyAdmin interface using the browser. The URL will be:

http://localhost/phpmyadmin

OR

http://your-ip-addr-ess/phpmyadmin

Log in with the database user we created in the previous step.

how to secure your phpMyAdmin installation.