What is the Ubuntu way to configure phpMyAdmin so that I can use it to administer multiple MySQL servers? The database parameters are set in /etc/dbconfig-common/phpmyadmin.conf, but there's only space in there for the connection parameters for a single server. I could hack it into /etc/phpmyadmin/config-db.php and /etc/phpmyadmin/config.inc.php, but I assume there has to be a more elegant way.

  • Have you ever found a sollution to do this? Did you hack into one of the files you've mentioned, or not? – Nanne Mar 31 '11 at 9:41
  • This tutorial explains how you can manage multiple MySQL servers from one phpMyAdmin installation. For security reasons, communication between phpMyAdmin and any remote MySQL server is using SSL encryption – user61928 Sep 21 '12 at 5:40

Fairly old question, but still relevant on searches.

phpMyAdmin uses plain PHP for config files, and the $cfg['Servers'] array to get the configured servers.

So the proper way is to add a new config file in /etc/phpmyadmin/conf.d for every server you want to add. It's only required to end the files name in .php to get them included, but it's a good idea to use your_new_server.inc.php for consistency.

The minimal contents for a given config file would be:

<?php // let the interpreter know this is code
$cfg['Servers'][2]['host']     = 'THE_HOST';
$cfg['Servers'][2]['user']     = 'THE_USER';
$cfg['Servers'][2]['password'] = 'THE_PASSWORD';

As stated in another answer, you can check the /usr/share/doc/phpmyadmin/examples/config.manyhosts.inc.php file for more parameters.

Important: You have to increase the index (2) of the array for every new file, and avoid using 1 if you want to keep connecting to localhost.

If the guy(s) that package(s) phpMyAdmin had thought about it, they could have added the incrementing $i variable in the foreach that includes the files from the conf.d directory, so you could just use it as the index and not worry about having to increase it manually, but sadly it's not the case. You can do it yourself though.

[2019]: Newer PHP versions allow this more succinct alternative syntax:

<?php $cfg['Servers'][] = ['host'=>'my_host', 'user'=>'my_user', 'password'=>'my_pass'];
| improve this answer | |
  • I tried putting the minimal content listed in /etc/phpmyadmin/conf.d/slaveA.conf.php and simply saw the contents at the top of the PHPMyAdmin page. When I catted that same contents into the bottom of config.inc.php it worked. Something about that include seems to be messing it up. Otherwise, this looks to be the expected way to create custom config that won't get killed in updates. – flickerfly Mar 1 '16 at 17:07
  • 1
    @flickerfly, late answer but the code in the config files has to start with <?php, as any other PHP script. – Marc Dec 15 '16 at 15:34

I think this is the most accurate way to do it:

First setup the password:

sudo htpasswd -c /etc/phpmyadmin/htpasswd.setup admin

Then disable security:

sudo pma-configure

Then go to http://yourserver/phpmyadmin/setup (here the browsers ask for auth, the user is admin and the password is what you write in first command), with that wizard you configure your servers, once is done, put the security again:

sudo pma-secure
| improve this answer | |
  • The config file generated by this method is stored in /var/lib/phpmyadmin/config.inc.php. – Michael Lawton May 9 '14 at 17:41
  • This config file generated by this method is then included in the main config file at /etc/phpmyadmin/config.inc.php. The phpMyAdmin setup script is buggy on Ubuntu and doesn't load the existing configuration (forcing you to start from scratch each time you configure it). Also the configuration it generates includes stuff like the blowfish secret which is then overwritten by the main config file. You will find that the first server (1) is overwritten by the main config file, which uses the server values from config-db.php. – Michael Lawton May 11 '14 at 16:22

I have assumed the following:

  • /etc/phpmyadmin/ would be the most logical place to add the config
  • /etc/phpmyadmin/config-db.php is the location for the default (local?) config. This is, because it is a default, one db only
  • /etc/phpmyadmin/config.inc.php reads the default database so it has one. At least this one is used, so you have a database. If something changes in your config, the config-db.php is changed, so 'local' changes to your file are not modified

Therefore my conclusion was that adding an extra server below this part:

/* Configure according to dbconfig-common if enabled */
if (!empty($dbname)) {
    //reading from config-db.php

//$i++ was allready done in if above
//Adding extra servers
 $cfg['Servers'][$i]['host'] = 'serverhost.host.tld';
 $cfg['Servers'][$i]['extension'] = 'mysqli';

This looks like the best place.

| improve this answer | |

According to the phpMyAdmin documentation you can define multiple servers in the $cfg['Servers'] array defined in the config.inc.php file.

| improve this answer | |
  • 2
    In a generic phpMyAdmin install, yes. But Ubuntu has its own configuration files to generate that part of the config.inc.php file, and I want to know the Ubuntu way to configure it, without having to override the Ubuntu configuration. – Mike Scott Jan 4 '11 at 9:57
  • I see. The comments in the file say You can regenerate it using: dpkg-reconfigure -plow phpmyadmin. I assume you tried that? (won't do it on production system now) Other than that ... manually changed files should be prompted on update before being overwritten. – Carsten Thiel Jan 4 '11 at 10:06
  • 2
    Yes, I can regenerate the file config-db.php, but the config file from which it sources the database connection parameters (/etc/dbconfig-common/phpmyadmin.conf) only has room to configure one database server. I want to know how to configure more than one database server. – Mike Scott Jan 4 '11 at 10:21
  • +Mike Scott, I couldn't get $cfg['Servers'] to work in a conf.d/ file, but when I put it in config.inc.php it worked fine. I'm thinking there is some bug that the include statement messes with it. – flickerfly Mar 1 '16 at 17:09

The main configuration file is stored in /etc/phpmyadmin/config.inc.php. This file includes the

  • Blowfish secret from /var/lib/phpmyadmin/blowfish_secret.inc.php
  • Generated config from phpMyAdmin setup script (diegueus9's method) /var/lib/phpmyadmin/config.inc.php
  • DB values from /etc/phpmyadmin/config-db.php which are generated from /etc/dbconfig-common/phpmyadmin.conf by /usr/sbin/dbconfig-generate-include. /etc/dbconfig-common/phpmyadmin.conf can be modified using dpkg-reconfigure -plow phpmyadmin
  • Extra configuration files from /etc/phpmyadmin/conf.d/*.php

Some example configuration snippets are in /usr/share/doc/phpmyadmin/examples including config.manyhosts.inc.php. This file can be added to /etc/phpmyadmin/conf.d. It works by resetting the i variable back to 1 before creating any hosts so that it overrides the host set in /etc/phpmyadmin/config.inc.php.

If you want to do a more advanced configuration, you will probably want to change the /etc/phpmyadmin/config.inc.php file and possibly add other configuration extensions using /etc/phpmyadmin/conf.d.

To add support for additional configurations to older configuration files, you can create the directory /etc/phpmyadmin/conf.d and then add the below PHP code to the bottom of /etc/phpmyadmin/config.inc.php:

/* Support additional configurations */
foreach (glob('/etc/phpmyadmin/conf.d/*.php') as $filename) {
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.