The configuration file that comes with phpMyAdmin has only one server configured which allows you to connect to localhost server only. In this short tutorial, we will show you how to add another host to phpMyAdmin configuration file.
First we need to check if the file "config.inc.php" exists or not. If the file exists, we will continue with the modifications. If the file does not exist, we will create the file using a template configuration file.
The "locate" command can be used to find files and directories by name. In order to use it, we need to update files and directories names databases.
To update the databases, run the following command:
The command might run for few minutes depending on the last time it was executed. Please wait until it is finished.
When the command is done executing, issue the following to look for phpMyAdmin configuration file.
If the file is found, continue to step 2 to edit the file to configure the second server.
If file is not found or nothing shown by the locate command, look for the template configuration file using the locate command as follow:
Navigate to the directory where the file is found. For example, if the locate command returned the following:
/usr/share/phpmyadmin/config.sample.inc.php, then navigate to the directory by issuing the following command:
Now duplicate the template file by copying it to another name as follow:
cp config.sample.inc.php config.inc.php
The configuration file is now created and ready to be edited.
In some phpMyAdmin distribution, the file "config.sample.inc.php" is located in another directory than the one used by the live version of phpMyAdmin. You will need to find the location of the live version of phpMyAdmin, copy the file to that location, and then issue the cp command above to duplicate it.
Use the nano command or any other editor to edit the configuration file. Type the following to edit the file:
Now add the following lines at the end of file. Make sure to replace XXX.XXX.XXX.XXX with MySQL server IP. Leave the port empty for default value unless you have the server on different port:
$i++; $cfg['Servers'][$i]['verbose'] = 'My Second Server'; $cfg['Servers'][$i]['host'] = 'XXX.XXX.XXX.XXX'; $cfg['Servers'][$i]['port'] = ''; $cfg['Servers'][$i]['socket'] = ''; $cfg['Servers'][$i]['connect_type'] = 'tcp'; $cfg['Servers'][$i]['extension'] = 'mysqli'; $cfg['Servers'][$i]['auth_type'] = 'cookie'; $cfg['Servers'][$i]['AllowNoPassword'] = false;
Press Ctrl+O and hit enter to save the file. Press Ctrl+x to exit the editor.
To test and check if the configuration is successful, launch the browser of your choice and access phpMyAdmin. You now have the choice to choose the server as shown below:
Or from inside phpMyAdmin as shown below: