How To Install phpMyAdmin with Nginx on Debian 10

porplague70

How To Install phpMyAdmin with Nginx on Debian 10

phpMyAdmin is a free and open-source, web-based tool for managing the MySQL and MariaDB servers. It is widely used to manage the database by web hosting companies and administrators who are new to the database.

phpMyAdmin helps the system administrator to perform databases activities such as creating, deleting, querying, database, tables, columns, etc.

In this post, we will see how to install phpMyAdmin with Nginx on Debian 10.

Prerequisites

Install MariaDB Server

To install phpMyAdmin, your system must have a database instance running and Nginx web server.

Standalone Database

Follow the below tutorials and prepare your system for setting up phpMyAdmin.

Step 1: How To Install MariaDB on Debian 10

Then,

Step 2: How To Install LEMP Stack on Debian 10You can skip the database part in Step 2 – LEMP stack tutorial if you have followed the Step 1 – MariaDB installation.

Install PHP extensions for phpMyAdmin to connect with database.

sudo apt install -y php-json php-mbstring

LEMP Stack

READ: How To Install LEMP Stack on Debian 10

Install PHP extensions for phpMyAdmin to connect with database.

sudo apt install -y php-json php-mbstring

Install phpMyAdmin

The phpMyAdmin is not available as Deb package in Debian OS repository for Debian 10. So, we will download the tarball from the official website.

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

Extract phpMyAdmin using the tar command.

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

Move the phpMyAdmin to your 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.

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

Generate a blowfish secret and update the secret in the configuration file.

$cfg['blowfish_secret'] = 'CfX1la/aG83gx1{7rADus,iqz8RzeV8x'; /* 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';

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 a virtual host configuration file for phpMyAdmin (Ex. phpMyAdmin.conf) under the /etc/nginx/conf.ddirectory.

sudo nano /etc/nginx/conf.d/phpMyAdmin.conf

Use the following information to create a virtual host for phpMyAdmin. Change the domain name (server_name) as per your requirement.

server {
   listen 80;
   server_name pma.itzgeek.local;
   root /usr/share/phpMyAdmin;

   location / {
      index index.php;
   }

## Images and static content is treated different
   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 127.0.0.1:9000;
      fastcgi_index index.php;
      fastcgi_param SCRIPT_FILENAME /usr/share/phpMyAdmin$fastcgi_script_name;
   }
}

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 the ownership of phpMyAdmin directory.

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

Restart the services.

sudo systemctl restart nginx 

sudo systemctl restart php7.3-fpm

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;

If required, you can disable Unix socket authentication and enable native password login.

Access phpMyAdmin

Access the phpMyAdmin using the browser by going to the below URL.http://your-fully-qualified-domain-name

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

Install phpMyAdmin with Nginx on Debian 10 - Login to phpMyAdmin
Install phpMyAdmin with Nginx on Debian 10 – Login to phpMyAdmin

You will get the home page where you can manage databases.

Install phpMyAdmin with Nginx on Debian 10 - phpMyAdmin
Install phpMyAdmin with Nginx on Debian 10 – phpMyAdmin

Sobre o Autor

plague70 administrator

Deixe uma resposta