How to Install phpMyAdmin in Debian 11

In this guide, we will demonstrate how phpMyAdmin is installed on a Debian 11 system. phpMyAdmin requires a standalone Database or as part of the LAMP stack, installed and running on the system before hand.

At the time of making this guide, phpMyAdmin 5.2 was latest, please Navigate to phpMyAdmin download page for latest version when installing and ensure you are on the latest version.

Prerequisites

Server with Apache, PHP, and MariaDB installed and running.

You can refer to the article we have for setting up LAMP Stack in case you do not have the required services running.

Updating the system

We first update the system to make sure that all our installed packages are up to 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 11 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://files.phpmyadmin.net/phpMyAdmin/5.2.1/phpMyAdmin-5.2.1-all-languages.tar.gz

Extract the downloaded file.

tar xvf phpMyAdmin-5.2.1-all-languages.tar.gz

Move the phpMyAdmin-5.2.1-all-languages to /usr/share/ directory.

mv phpMyAdmin-5.2.1-all-languages /usr/share/phpmyadmin

Configuring phpMyAdmin

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

Install and use the pwgen program to generate a random string,

apt install pwgen

Generate Random a Password,

pwgen -s 32 1

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", use the random 32 character generated above instead.

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

Finally, 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 preferred password.

GRANT SELECT, INSERT, UPDATE, DELETE ON phpmyadmin.* TO 'pma'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON phpmyadmin.* TO 'pma'@'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION;
exit;

Output:

root@server:~# mariadb
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 53
Server version: 10.5.11-MariaDB-1 Debian 11

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 'password';
Query OK, 0 rows affected (0.003 sec)

MariaDB [(none)]> GRANT ALL PRIVILEGES ON phpmyadmin.* TO 'pma'@'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION;
Query OK, 0 rows affected (0.001 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

Open your browser's address bar to check if phpMyAdmin is installed: http://yourserver-ip-address/phpmyadmin/.

You should see a page similar to the screenshot shown below,

image

Done!


CrownCloud - Get a SSD powered KVM VPS at $4.5/month!
Use the code WELCOME for 10% off!

1 GB RAM / 25 GB SSD / 1 CPU Core / 1 TB Bandwidth per month

Available Locations: LAX | MIA | ATL | FRA | AMS