Install phpmyadmin in Debian 10

From this tutorial you will learn how to install phpmyadmin Debian 10 with Apache, MariaDB, PHP (LAMP stack). phpMyAdmin is a free web tool for database management, open source, written in PHP. It provides a convenient interface for database management MySQL or MariaDB.

We’ll also learn how to enable basic authentication for the web server for phpMyAdmin. For starters, you’ll need Debian OS 10, running on your local computer or on a remote server.

Install phpmyadmin in Debian 10

Assume that you have already installed the LAMP stack on Debian. If not, consult the respective user manual.

Please note that you need to be root when installing software in Debian. You can add sudo in front of the command or use the command su – to switch to root user. With this understood, now let’s start installing phpMyAdmin.

Step 1: Download phpMyAdmin

PhpMyAdmin is not included in the software repository of the Debian 10, so we have to download it from phpmyadmin.net using the following commands.

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

Hint: You can always use the above URL format to download the latest stable version of phpMyAdmin. Just replace 4.9.0.1 on the latest version number.

And extract it:

sudo apt install unzip

unzip phpMyAdmin-4.9.0.1-all-languages.zip

4.9 move phpMyadmin to /usr/share/:

sudo mv phpMyAdmin-4.9.0.1-all-languages /usr/share/phpmyadmin

Then make the user the web server (www-data) the owner of this directory.

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

Step 2: Create the database and user

Now we need to log on to the console MariaDB and create a database and user for phpMyAdmin. By default, the MariaDB package in Debian uses unix_socket to authenticate the user login, which basically means that you can use the user name and OS password to log into MariaDB console. Thus, you can run the following command to login without providing the root password for MariaDB.

sudo mysql-u root

Then create a new database for phpMyAdmin using the following SQL command. We call it phpmyadmin, you can use any name for the database.

Phpmyadmin CREATE DATABASE DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

The following SQL command will create a database user phpmyadmin and set the password, and at the same time will grant all the permissions of the new database a new user to phpMyAdmin later could write to the database. Replace the text highlighted in red for your password.

GRANT ALL ON phpmyadmin.* TO 'phpmyadmin'@'localhost' IDENTIFIED BY 'vash_parol';

Update the privilege table and exit from the MariaDB console.

FLUSH PRIVILEGES;
EXIT;

Step 3: Install the PHP modules

Run the following command to install the PHP modules required or recommended by phpMyAdmin:

sudo apt install php-imagick php-phpseclib-php-php-gettext php7.3-common php7.3-gd php7.3-imap php7.3-json php7.3-curl php7.3-zip php7.3-xml php7.3-mbstring php7.3-bz2 php7.3-intl php7.3-gmp

Then restart Apache:

sudo systemctl restart apache2

Step 4. Configuring Apache

If you want to access the web interface of phpMyAdmin from a subdirectory, create a configuration fragment using the following commands.

sudo 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>pen_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>
# 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>
<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>pen_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>
# 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>
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>
# 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 snippet:

sudo a2enconf phpmyadmin.conf

We also need to create a temporary folder phpMyAdmin:

sudo mkdir -p /var/lib/phpmyadmin/tmp

sudo chown www-data:www-data /var/lib/phpmyadmin/tmp

Restart Apache so the changes take effect:

sudo systemctl reload apache2

Now you can access the web interface of phpMyAdmin at:

http://ip_адрес/phpmyadmin

If phpMyAdmin is installed on your local machine Debian, you can access the web interface of phpMyAdmin by typing the following text into the address bar of your browser:

http://localhost/phpmyadmin

If connection refused or failed to install, perhaps there is a firewall that prevents HTTP requests. If you have a firewall iptables, you need to run the following command to open TCP ports 80 and 443.

sudo iptables-I INPUT -p tcp --dport 80 -j ACCEPT

sudo iptables-I INPUT-p tcp --dport 443 -j ACCEPT

If you have a firewall, UFW, run this command to open TCP ports 80 and 443:

sudo ufw allow http

sudo ufw allow https

Step 5: Run the installation script

Enter the following in the browser address bar:

ip_address/phpmyadmin/setup

Or:

localhost/setup

Click New serverto configure the server. Then just click Apply. Then click Displayto display the configuration file.

In /usr/share/phpmyadmin/ create a file config.inc.php:

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

Copy the contents of the file config.inc.php from the page setup phpMyAdmin and paste it in the file /usr/share/phpmyadmin/config.inc.php.

Step 6: Create the administrator

Now, if you try to login to phpMyAdmin with the root user account MariaDB, you can see the following error.

#1698 - Access denied for user 'root '@'localhost'

And also:

mysqli_real_connect(): (HY000/1698): Access denied for user 'root '@'localhost'

If you are logged in with the user phpmyadmin, you will not see the above error. However, you can use phpmyadmin to manage the database, phpmyadmin. The cause of the error is that by default the root user of MariaDB is authenticated using the plugin unix_socket, not using the plugin mysql_native_password. To solve this problem, we can create another administrator user and grant all privileges to the new user-administrator.

Log on to the MariaDB server from the command line.

sudo mysql-u root

Create user admin with password authentication.

CREATE USER [email protected] IDENTIFIED BY 'newPassword';

Grant all privileges to all databases.

GRANT ALL PRIVILEGES *.* TO [email protected] WITH GRANT OPTION;

Flush the privileges and exit;

FLUSH PRIVILEGES;

EXIT;

Now you can login to phpMyAmin with an administrator account and manage all databases.

Step 7: Configure storage settings

Now in phpMyAdmin control panel you may see a warning message.

The phpMyAdmin configuration storage is not completely configured, some extended features have been deactivated. Find out why.
Or alternately go to 'Operations' tab of any database to set it up there.

Click on the link to Find out why. Then press Create to create database table phpmyadmin.

Step 8: Restricting access to the directory /setup

To restrict access to the directory /setup, we can enable basic password authentication with the Apache web server. Run the following command to set the password for the admin user. The file /etc/apache2/htpasswd is used to store user names and passwords.

sudo htpasswd -c /etc/apache2/htpasswd admin

Then edit the Apache configuration file for phpMyAdmin

sudo vi /etc/apache2/sites-available/phpmyadmin-le-ssl.conf

Add the following lines.

# 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/apache2/htpasswd
</IfModule>
Require valid-user
</IfModule>
</Directory>

Save and close the file. Then restart Apache so the changes take effect:

sudo systemctl reload apache2

If you re-open the script installer phpMyAdmin, you will be prompted to enter a user name and password. Similarly, you can protect phpMyAdmin completely, you just need to fix the path.

Insights

In this article we discussed how to install Phpmyadmin Debian 10 Buster manually. The same instructions can be used for other distributions.

Source: losst.ru

(Visited 170 times, 1 visits today)