Article overview

Help article

installing and configuring phpMyAdmin in Debian 9

phpMyAdmin is a web interface, intended to make managing MySQL / MariaDB databases over the internet easier. Common SQL actions, such as the management of databases, tables, columns, users, permissions, etc. can be performed from the phpMyAdmin web interface.

In this article, we show you how to install phpMyAdmin on a VPS with Debian 9 and how to fix a bug which you may encounter during use.

  • Follow the steps in this article as a root user or use sudo.
     
  • The steps in this article require a database and web server on your VPS. For example, you can use our manuals for MariaDB and Apache if you have not yet installed a web server.

Installing phpMyAdmin

 

Step 1

Connect to your VPS via SSH or use the VPS console and update your server first:

apt -y update
apt -y upgrade

It is recommended to reboot your VPS after an update and then to run these commands again. If you've just installed a kernel update as well with the commands above some software may not be available until you've restarted your server.


 

Step 2

As part of the installation, a database is created for phpMyAdmin. While writing this manual, we encountered a problem where 'debian-sys-maint' @ 'localhost' has no rights to that database, despite debian-sys-maint having full rights to all databases by default. This problem is probably due to the fact that the database in question does not yet exist at the time the check is performed. To prevent this, it is advisable to first create the database manually and to grant the necessary rights.

Start an SQL shell:

mysql -u root -p

 

Step 3

Create a database for phpMyAdmin, for example:

CREATE DATABASE phpmyadmin;

 

Step 4

Give 'debian-sys-maint'@'localhost' full rights to the new database:

GRANT ALL ON phpmyadmin.* TO 'debian-sys-maint'@'LOCALHOST';

 

Step 5

Then close the SQL shell with:

exit;

 

Step 6

In step 7 you will be asked which web server you use. If you are unsure whether / which web server you use, you can first check this with:

systemctl status apache2
systemctl status lighttpd

If you see the message 'Unit apache2/lighttpd.service not found' then that specific software is not present on your server. Do both services show this output? Then, first install Apache before proceeding.

When ready, start the phpMyAdmin installation with the command:

apt -y install phpmyadmin

 

Step 7

During the installation process, you will see a number of windows for the configuration of phpMyAdmin. The first is which web server you use:

configuring phpmyadmin webserver


 

Step 8

You will now be asked to create a database that will be used by phpMyAdmin. Without this database, phpMyAdmin will not work, so choose 'Yes' here.

configuring phpmyadmin dbconfig common


 

Step 9

phpMyAdmin also requires a password for the database created in step 4. Set a unique password and click 'Enter' to continue and confirm the password again.

configuring phpmyadmin password


 

Step 10

Your installation is now ready! You can immediately try phpMyAdmin by going to your hostname / phpmyadmin in your browser, for example, server.example.com/phpmyadmin. If necessary, check your hostname with one of the following commands:

cat /etc/hosts
hostnamectl

For logging in, you can use one of your SQL users, which you retrieve from the SQL shell (see step 2) with the command:

SELECT host,user,password,Grant_priv,Super_priv FROM mysql.user;

For an overview of commonly used MariaDB- / MySQL commands, see this article. For example, you can use the explanation therein about adding data to a table in the 'SQL' tab in phpMyAdmin, see: 

phpmyadmin sql query

Important: at the time of writing, there is a bug in phpMyAdmin upon opening tables. We will explain the bug in more detail in the following section. Check whether you are also experiencing this bug by opening a random table of a database in phpMyAdmin. If so, follow the steps in the section below.   


Warning in ./libraries/sql.lib.php#613 count (): Parameter must be an array or an object that implements Countable 

While writing this tutorial, there appeared to be a bug in phpMyAdmin, causing you to see the above error message or the following message:

This is caused by a piece of code is incorrectly closed in the /usr/share/phpmyadmin/libraries/sql.lib.php file (see 'Manual solution').

 

The quick solution

The simplest solution is to use the following commands to adjust the erroneous code (note the scroll bar):

sed -i 's/(count($analyzed_sql_results\['\''select_expr'\''\] == 1)/(count($analyzed_sql_results\['\''select_expr'\''\]) == 1)/g' /usr/share/phpmyadmin/libraries/sql.lib.php
sed -i 's/($analyzed_sql_results\['\''select_expr'\''\]\[0\] == '\''[*]'\'')))/($analyzed_sql_results\['\''select_expr'\''\]\[0\] == '\''[*]'\''))/g' /usr/share/phpmyadmin/libraries/sql.lib.php
systemctl restart apache2

 

Manual solution

You can also solve the problem by correcting the erroneous code yourself. First, open the file /usr/share/phpmyadmin/libraries/sql.lib.php:

nano /usr/share/phpmyadmin/libraries/sql.lib.php

The sql.lib.php file shows the following code on lines 612, 613 and 614:

((empty($analyzed_sql_results['select_expr']))
    || (count($analyzed_sql_results['select_expr'] == 1)
        && ($analyzed_sql_results['select_expr'][0] == '*')))

On the second line, ['select_expr'] is not closed with a parenthesis, and the missing parenthesis has been moved to the end of the third line. The correct code is therefore: 

((empty($analyzed_sql_results['select_expr']))
    || (count($analyzed_sql_results['select_expr']) == 1)
        && ($analyzed_sql_results['select_expr'][0] == '*'))

Restart Apache after changing the code to process the changes:

systemctl restart apache2

 

 

Should you have any questions left regarding this article, do not hesitate to contact our support department. You can reach them via the ‘ContactUs’ button at the bottom of this page.

If you want to discuss this article with other users, please leave a message under 'Comments'.

Has this article been helpful?

Create an account or log in to leave a rating.

Comments

Create an account or log in to be able to leave a comment.