How to Disable root Login Access to PhpMyAdmin

If you are planning on using phpmyadmin on a regular basis to manage your databases over the network (or worse, over the Internet!), you don’t want to use the root account. This is valid not only for phpmyadmin but also for any other web-based interface.

In /etc/phpmyadmin/config.inc.php, look for the following line and make sure the AllowRoot directive is set to FALSE:

$cfg['Servers'][$i]['AllowRoot'] = FALSE;
Disable Root Login in PhpMyAdmin
Disable Root Login in PhpMyAdmin

In Ubuntu/Debian, you need to add these two lines as shown:

/* Authentication type */
$cfg['Servers'][$i]['auth_type'] = 'cookie';
$cfg['Servers'][$i]['AllowRoot'] = false;

Save changes and restart Apache.

------------- On CentOS/RHEL Systems -------------
# systemctl restart httpd.service

------------- On Debian/Ubuntu Systems -------------
# systemctl restart apache2.service

Then follow the steps outlined in the above tips to get to the phpmyadmin login page (https://<ip address>/phpmyadmin) and Try to login as root:

Root Access Disabled in Phpmyadmin
Root Access Disabled in Phpmyadmin

Then connect to your MySQL / MariaDB database via the command prompt and, using root credentials, create as many accounts as needed to access one database each. In this case we will create an account named jdoe with password jdoespassword:

# mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 24
Server version: 10.1.14-MariaDB MariaDB Server

Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> CREATE USER 'jdoe'@'localhost' IDENTIFIED BY 'jdoespassword';
Query OK, 0 rows affected (0.04 sec)

MariaDB [(none)]> GRANT ALL PRIVILEGES ON gestion.* to 'jdoe'@'localhost';
Query OK, 0 rows affected (0.00 sec)

Then let’s login using the above credentials. As you can see, this account only has access to only one database:

Enable PhpMyAdmin Access to User
Enable PhpMyAdmin Access to User

Congratulations! You have disabled root access to your phpmyadmin installation and can now use it to manage your databases.

I strongly recommend you to add an extra layer of security to your phpmyadmin installation with .htaccess password protection and setup HTTPS (SSL certificate) to avoid sending username and password in plain text format over network.

If this article helped, with someone on your team.

TecMint Weekly Newsletter
Get the Learn Linux 7 Days Crash Course free when you join 34,000+ Linux professionals reading every Thursday.
Check your email for a magic link to get started.
Something went wrong. Please try again.
TecMint has been free for 14 years. Help keep it that way.
Google AI Overviews and tools like ChatGPT have cut into search traffic for independent tech sites like TecMint. Running this site costs over $2,000 every month for hosting, infrastructure, and paying authors to keep the content accurate and tested.

If this article helped you solve a problem, consider buying a coffee. It helps keep TecMint free, supports the authors, and keeps the project going.
☕ Buy Me a Coffee
Gabriel Cánepa
Gabriel Cánepa is a GNU/Linux sysadmin and web developer from Villa Mercedes, San Luis, Argentina. He works for a worldwide leading consumer product company and takes great pleasure in using FOSS tools to increase productivity in all areas of his daily work.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

4 Comments

Leave a Reply
  1. What if MySQL administrator account is not called root? I mean, it’s not like `root` if of any special meaning to mySQL.

    Reply
  2. This whole series is awesome, and a big help. I had inherited a set up with phpMyAdmin with every virtual host using root access to the databases, including my live site. What I did and would recommend is that if your site is being used while you’re taking these steps, create the users and their passwords first, test them, then update your php code to use the new usernames. Then when you put the bash on root access you don’t have to scramble to get the new connection code in place.

    Reply

Got Something to Say? Join the Discussion...

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.

Free Course
Get a free Linux course before you go.
Subscribe to TecMint Weekly and get the Learn Linux 7 Days Crash Course free. Read by 34,000+ Linux professionals every Thursday.
Something went wrong. Please try again.
Check your email for a magic link to get started.