How to Install phpMyAdmin in Debian 10

phpMyAdmin is a free, open-source web application for managing and administering MySQL and MariaDB databases. It provides an easy-to-use graphical user interface that allows users to perform a wide range of database management tasks, such as creating and modifying tables, running queries, importing and exporting data, and managing users and permissions.

phpMyAdmin is written in PHP and can be installed on any web server that supports PHP and MySQL. It is a popular tool among developers, database administrators, and webmasters who work with MySQL or MariaDB databases. With phpMyAdmin, managing and administering databases becomes much easier and more efficient, even for users with little or no experience with command-line interfaces.

Prerequisites:

Server with Apache, PHP and MariaDB. We also have the guide for LAMP Stack as well.

Updating the system

We first update the system to make sure that all our installed packages are upto date. Your Debian system can be updated easily with the following command.

apt update

apt upgrade

Install the required phpMyAdmin packages.

apt install php-mbstring php-zip php-gd

Downloading phpMyAdmin

phpMyAdmin isn’t included in Debian 10 software repository, so you'll need to manually download the software. Navigate to phpMyAdmin download page to check the latest stable version. Then run the following command to download it.

wget https://www.phpmyadmin.net/downloads/phpMyAdmin-latest-all-languages.tar.gz -O PHPMyAdmin.tar.gz

Extract the downloaded file.

tar xvf PHPMyAdmin.tar.gz

Move the phpMyAdmin-* to /usr/share/ directory.

mv phpMyAdmin-* /usr/share/phpmyadmin

Configuring phpMyAdmin

Let's create a temporary directory for phpMyAdmin storage, create a sub-directroy with the following command.

mkdir -p /var/lib/phpmyadmin/tmp

Make the web server user www-data as the owner of this directory.

chown -R www-data:www-data /var/lib/phpmyadmin

Make a copy to the file /usr/share/phpmyadmin/config.inc.php

cp /usr/share/phpmyadmin/config.sample.inc.php /usr/share/phpmyadmin/config.inc.php

Edit the /usr/share/phpmyadmin/config.inc.php file as follows using preferred text editor.

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

Enter a string of 32 random characters in between single quotes.

$cfg['blowfish_secret'] = 'STRINGOFTHIRTYTWORANDOMCHARACTERS'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */

Note: Do not re-use "STRINGOFTHIRTYTWORANDOMCHARACTERS", generate a random 32 character string and use.

Install and use the pwgen program.

apt install pwgen

Generate Random a Password.

pwgen -s 32 1

Then uncomment this section of the /usr/share/phpmyadmin/config.inc.php file will look like as follows:

/* 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';

Add the following line to bottom of the file.

$cfg['TempDir'] = '/var/lib/phpmyadmin/tmp';

Then save & exit the file.

Create a MariaDB Database and User for phpMyAdmin

Create the configuration storage database and tables by running the following command.

mariadb < /usr/share/phpmyadmin/sql/create_tables.sql

Open the MariaDB prompt.

mariadb

Create the pma user and grant it the appropriate permissions and Replace texts with your perferred password.

GRANT SELECT, INSERT, UPDATE, DELETE ON phpmyadmin.* TO 'pma'@'localhost' IDENTIFIED BY 'password';

GRANT ALL PRIVILEGES ON *.* TO 'john'@'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION;

exit;

Output:

root@vps:~# mariadb
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 59
Server version: 10.3.27-MariaDB-0+deb10u1 Debian 10

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> GRANT SELECT, INSERT, UPDATE, DELETE ON phpmyadmin.* TO 'pma'@'localhost' IDENTIFIED BY 'rf115Tkg7M3E3TDhwDZQSKjsAMq0rccU';
Query OK, 0 rows affected (0.006 sec)

MariaDB [(none)]> GRANT ALL PRIVILEGES ON *.* TO 'john'@'localhost' IDENTIFIED BY '15rn9KH' WITH GRANT OPTION;
Query OK, 0 rows affected (0.005 sec)

MariaDB [(none)]> exit;
Bye

Create Apache Configuration for phpMyAdmin

Create a configuration file with the following command.

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

Paste the following text into the file.

# phpMyAdmin default Apache configuration

Alias /phpmyadmin /usr/share/phpmyadmin

<Directory /usr/share/phpmyadmin>
    Options SymLinksIfOwnerMatch
    DirectoryIndex index.php

    <IfModule mod_php5.c>
        <IfModule mod_mime.c>
            AddType application/x-httpd-php .php
        </IfModule>
        <FilesMatch ".+\.php$">
            SetHandler application/x-httpd-php
        </FilesMatch>

        php_value include_path .
        php_admin_value upload_tmp_dir /var/lib/phpmyadmin/tmp
        php_admin_value open_basedir /usr/share/phpmyadmin/:/etc/phpmyadmin/:/var/lib/phpmyadmin/:/usr/share/php/php-gettext/:/usr/share/php/php-php-gettext/:/usr/share/javascript/:/usr/share/php/tcpdf/:/usr/share/doc/phpmyadmin/:/usr/share/php/phpseclib/
        php_admin_value mbstring.func_overload 0
    </IfModule>
    <IfModule mod_php.c>
        <IfModule mod_mime.c>
            AddType application/x-httpd-php .php
        </IfModule>
        <FilesMatch ".+\.php$">
            SetHandler application/x-httpd-php
        </FilesMatch>

        php_value include_path .
        php_admin_value upload_tmp_dir /var/lib/phpmyadmin/tmp
        php_admin_value open_basedir /usr/share/phpmyadmin/:/etc/phpmyadmin/:/var/lib/phpmyadmin/:/usr/share/php/php-gettext/:/usr/share/php/php-php-gettext/:/usr/share/javascript/:/usr/share/php/tcpdf/:/usr/share/doc/phpmyadmin/:/usr/share/php/phpseclib/
        php_admin_value mbstring.func_overload 0
    </IfModule>

</Directory>

# Authorize for setup
<Directory /usr/share/phpmyadmin/setup>
    <IfModule mod_authz_core.c>
        <IfModule mod_authn_file.c>
            AuthType Basic
            AuthName "phpMyAdmin Setup"
            AuthUserFile /etc/phpmyadmin/htpasswd.setup
        </IfModule>
        Require valid-user
    </IfModule>
</Directory>

# Disallow web access to directories that don't need it
<Directory /usr/share/phpmyadmin/templates>
    Require all denied
</Directory>
<Directory /usr/share/phpmyadmin/libraries>
    Require all denied
</Directory>
<Directory /usr/share/phpmyadmin/setup/lib>
    Require all denied
</Directory>

Save and close the file. Then enable this configuration.

a2enconf phpmyadmin.conf

Reload Apache for the changes to take effect.

systemctl reload apache2

Enter it into your browser's address bar to check phpmyadmin is installed. http://yourserver-ip-address/phpmyadmin/. You should see a page similar to below one.

image

Done!