How to configure phpMyAdmin to access multiple servers?
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.
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'];
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