How to install phpMyAdmin with nginx on Debian 11

5
(1)

In this guide, we will show you how to install phpMyAdmin with Nginx on Debian 11. For those of you who didn’t know, phpMyAdmin is a free and open source web application used to manage MySQL databases and user accounts. , and privileges, executing SQL statements, importing and exporting data in various data formats, and much more from the web interface. This article assumes you have at least basic knowledge of Linux, you know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes that you are running as root, otherwise you may need to add ‘ sudo ‘ to the commands to gain root privileges. I will show you a step by step installation of phpMyAdmin on Debian 11 (Bullseye).

  1. Check system and packages
sudo apt update
sudo apt upgrade

Now we create a new superuser account for phpMyAdmin only:

Under user root type in mysql console:

MariaDB> CREATE DATABASE app_db;
MariaDB> CREATE USER 'app_user'@'localhost' IDENTIFIED BY 'your-strong-password';
MariaDB> GRANT ALL PRIVILEGES ON app_db.* TO 'app_user'@'localhost' WITH GRANT OPTION;
MariaDB> FLUSH PRIVILEGES;
MariaDB> EXIT;

2. Setup phpmyadmin

By default, phpMyAdmin is not available in the Debian 11 Bullseye repository, so you need to manually download phpMyAdmin from the official page:

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

Then extract the phpMyAdmin archive to the root directory of home directory:

tar xvf phpMyAdmin-5.2.0-all-languages.tar.gz
sudo mv phpMyAdmin-5.2.0-all-languages /usr/share/phpmyadmin

We now copy the sample phpMyAdmin configuration file and rename it as follows:

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

Then edit the config file:

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

Create a blowfish secret and update the secret in the config file:

$cfg['blowfish_secret'] = 'eDjtEzAk8N3Rk}AFY.vBW}UtYu8VPbGo'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */

Also uncomment the phpMyAdmin storage settings:

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

Set up a database and user for phpMyAdmin.

Now we create the configuration store database and tables by running the following command:

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

Then connect to the MariaDB shell with the following command:

sudo mysql -u root -p

Once connected, grant all necessary privileges to the phpMyAdmin database:

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

Set up Nginx for phpMyAdmin

It is assumed that you have already installed the nginx web-server and php-fpm.Edit /etc/nginx/sites-available/default

$ sudo nano /etc/nginx/sites-available/default

Insert into server section:

location /phpmyadmin {
    alias /usr/share/phpmyadmin/;

    location ~ /(libraries|setup) {
        return 404;
    }

    location ~ ^/phpmyadmin/(.*\.php)$ {
        alias /usr/share/phpmyadmin/$1;
        fastcgi_pass unix:/run/php/php8.0-fpm.sock;
        #fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $request_filename;
    }
    location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
        root /usr/share/;
    }
}

Save it.

Save and close, then create a tmp directory for phpMyAdmin and then change the permission:

sudo mkdir /usr/share/phpmyadmin/tmp
sudo chmod 777 /usr/share/phpmyadmin/tmp

Set access rights:

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

After successful installation, open a browser and follow the link and your phpMyAdmin will ask you for a user and password for your MySQL installation, you can use root as the MySQL root user and password. http://your-nginx-default-host/phpmyadmin/

Congratulations! You have successfully installed phpMyAdmin . Thank you for using this guide to install the latest version of phpMyAdmin with Nginx on Debian 11 Bullseye.

Similar Posts:

1,969

How useful was this post?

Click on a star to rate it!

Average rating 5 / 5. Vote count: 1

No votes so far! Be the first to rate this post.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top