Ech0 - 00 / 00 / 00

PHPMyAdmin with MariaDB + NGINX

Initial Setup

First we install the required dependencies:


apt update -y ; apt upgrade -y ; apt install nginx mariadb-server unzip vim php7.3-{mbstring,json,fpm,cli,mysql,xml}
cd /var/www
mkdir phpmyadmin
wget https://files.phpmyadmin.net/phpMyAdmin/5.1.0/phpMyAdmin-5.1.0-all-languages.zip -O /var/www/phpmyadmin/phpmyadmin.zip
cd phpmyadmin
unzip phpmyadmin.zip
mv phpMyAdmin-5.1.0-all-languages/ phpmyadmin
	

So now we get the following:


cd /var/www/phpmyadmin/phpmyadmin/

root@debian-phpmyadmin:/var/www/phpmyadmin/phpmyadmin# ls -lash
total 680K
4.0K drwxr-xr-x 12 root root 4.0K Feb 24 01:05 .
4.0K drwxr-xr-x  3 root root 4.0K Mar 26 19:03 ..
4.0K -rw-r--r--  1 root root 2.6K Feb 24 01:05 CONTRIBUTING.md
 44K -rw-r--r--  1 root root  41K Feb 24 01:05 ChangeLog
 20K -rw-r--r--  1 root root  18K Feb 24 01:05 LICENSE
4.0K -rw-r--r--  1 root root 1.5K Feb 24 01:05 README
4.0K -rw-r--r--  1 root root   29 Feb 24 01:05 RELEASE-DATE-5.1.0
4.0K -rw-r--r--  1 root root   41 Feb 24 01:05 babel.config.json
8.0K -rw-r--r--  1 root root 4.1K Feb 24 01:05 composer.json
200K -rw-r--r--  1 root root 197K Feb 24 01:05 composer.lock
8.0K -rw-r--r--  1 root root 4.4K Feb 24 01:05 config.sample.inc.php
4.0K drwxr-xr-x  3 root root 4.0K Feb 24 01:05 doc
4.0K drwxr-xr-x  2 root root 4.0K Feb 24 01:05 examples
 24K -rw-r--r--  1 root root  22K Feb 24 01:05 favicon.ico
4.0K -rw-r--r--  1 root root  413 Feb 24 01:05 index.php
4.0K drwxr-xr-x  5 root root 4.0K Feb 24 01:05 js
4.0K drwxr-xr-x  5 root root 4.0K Feb 24 01:05 libraries
4.0K drwxr-xr-x 45 root root 4.0K Feb 24 01:05 locale
4.0K -rw-r--r--  1 root root 2.3K Feb 24 01:05 package.json
4.0K -rw-r--r--  1 root root 1.1K Feb 24 01:05 print.css
4.0K -rw-r--r--  1 root root   26 Feb 24 01:05 robots.txt
4.0K drwxr-xr-x  3 root root 4.0K Feb 24 01:05 setup
4.0K -rw-r--r--  1 root root 1.4K Feb 24 01:05 show_config_errors.php
4.0K drwxr-xr-x  2 root root 4.0K Feb 24 01:05 sql
4.0K drwxr-xr-x 25 root root 4.0K Feb 24 01:05 templates
4.0K drwxr-xr-x  5 root root 4.0K Feb 24 01:05 themes
4.0K -rw-r--r--  1 root root 1.6K Feb 24 01:05 url.php
4.0K drwxr-xr-x 17 root root 4.0K Feb 24 01:05 vendor
288K -rw-r--r--  1 root root 287K Feb 24 01:05 yarn.lock

in here we need to create our config.inc.php from the config.sample.inc.php file:


cp config.sample.inc.php config.inc.php
vim config.inc.php
	

in here we need to generate a random blowfish secret:


[ 192.168.0.18/24 ] [ /dev/pts/25 ] [~]
→ pwgen -1 32
aelu2mi0raejae7loobu2pohbod3Iami
	

Edit the following line in config.inc.php:


$cfg['blowfish_secret'] = 'aelu2mi0raejae7loobu2pohbod3Iami'; 
	

then uncomment the following lines (make sure to correctly edit the first one):


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

Configuring nginx + mariadb




root@debian-phpmyadmin:/var/www/phpmyadmin/phpmyadmin# ls sql/create_tables.sql
sql/create_tables.sql

root@debian-phpmyadmin:/var/www/phpmyadmin/phpmyadmin# mysql < sql/create_tables.sql -u root -p
Enter password:


# HERE YOU CAN CHANGE THE NAME OF THE USERNAME AND PASSWORD !
#
# user : pma
# pass : pmapass
#
# i left them as default for this tutorial


root@debian-phpmyadmin:/var/www/phpmyadmin/phpmyadmin# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 50
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 ALL PRIVILEGES ON phpmyadmin.* TO 'pma'@'localhost' IDENTIFIED BY 'pmapass'; FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.001 sec)

Query OK, 0 rows affected (0.000 sec)
	

Next we will configure nginx:


MariaDB [(none)]> exit
Bye
root@debian-phpmyadmin:/var/www/phpmyadmin/phpmyadmin# vim /etc/nginx/sites-available/phpmyadmin.conf
	

:wq to save and quit, then import create_tables.sql into mysql:


server {
   listen 80;
   root /var/www/phpmyadmin/phpmyadmin;

   location / {
      index index.php;
   }

   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 unix:/var/run/php/php7.3-fpm.sock;
      fastcgi_index index.php;
      fastcgi_param SCRIPT_FILENAME /var/www/phpmyadmin/phpmyadmin$fastcgi_script_name;
   }
}

:wq to save and quit, then create a symlink to activate the site config file and remove the default config:


vim /etc/nginx/sites-available/phpmyadmin.conf
ln -s /etc/nginx/sites-available/phpmyadmin.conf /etc/nginx/sites-enabled/
rm /etc/nginx/sites-available/default
rm /etc/nginx/sites-en/default
rm /etc/nginx/sites-enabled/default


root@debian-phpmyadmin:/var/www/phpmyadmin/phpmyadmin# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Now that the site configuration is correct, we create phpmyadmin's tmp directory and set the permissions right:


root@debian-phpmyadmin:/var/www/phpmyadmin/phpmyadmin# mkdir tmp
root@debian-phpmyadmin:/var/www/phpmyadmin/phpmyadmin# chmod 777 tmp
root@debian-phpmyadmin:/var/www/phpmyadmin/phpmyadmin# chown -R www-data. /var/www/phpmyadmin/
	

root@debian-phpmyadmin:/var/www/phpmyadmin/phpmyadmin# systemctl restart nginx php7.3-fpm

root@debian-phpmyadmin:/var/www/phpmyadmin/phpmyadmin# ip a | grep inet
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host
    inet 10.0.0.113/16 brd 10.0.255.255 scope global eth0
    inet6 fe80::489f:58ff:fe8b:f1d6/64 scope link
	

Now that's done, we create a blank database inside of mysql:


root@debian-phpmyadmin:/var/www/phpmyadmin/phpmyadmin# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 51
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)]> CREATE DATABASE app_db;
Query OK, 1 row affected (0.001 sec)

MariaDB [(none)]> GRANT ALL PRIVILEGES ON app_db.* TO 'app_user'@'localhost' IDENTIFIED BY 'password';
Query OK, 0 rows affected (0.001 sec)

MariaDB [(none)]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.001 sec)

MariaDB [(none)]> EXIT;
Bye

End Result



Now that's done login to your phpmyadmin web interface with the credentials you set earlier (pma:pmapass):

And once logged in we get the following:

And that's it! We have been able to install PHPMyAdmin.

My Bunker

Some Address 67120,
Duttlenheim, France.

About Ech0

This cute theme was created to showcase your work in a simple way. Use it wisely.