Blog

Mysql SSH tunneling and PhpMyAdmin on Debian

It took me again some times to have this set up.

First you need obviously to have apache2 php and phpmyadmin installed on your box.
Once done, here are the things to do.

Configure phpmyadmin to use the tcp connection, always

To do so you will have to create the config.inc.php sitting for Debian in /etc/phpmyadmin/
By default this file is not created. You can create it manually or by executing a script as described here.
You will execute the /usr/sbin/pma-configure, which will create the config.inc.php that will be used by phpmyadmin. Note that this script doesn’t put the file in the correct location. Later once happy with your config, you will have to copy it from /var/lib/phpmyadmin/config.inc.php to /etc/phpmyadmin/config.inc.php.

So once the file created you can access to http://localhost/phpmyadmin/setup.
Here you will configure one server. The main thing here is to have the host to be the local IP address, ie 127.0.0.1 instead of localhost. It seems that if you use localhost, mysql will try to be smart and connect through a socket connection instead of the tcp ( found here)

Here is an exemple of the configuration done

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/* Servers configuration */ $i = 0;

/* Server: Local Host [1] */
$i++;
$cfg['Servers'][$i]['verbose'] = 'Local Host';
$cfg['Servers'][$i]['host'] = '127.0.0.1';
$cfg['Servers'][$i]['port'] = 3306;
$cfg['Servers'][$i]['socket'] = '';
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['extension'] = 'mysqli';
$cfg['Servers'][$i]['auth_type'] = 'config';
$cfg['Servers'][$i]['user'] = 'user';
$cfg['Servers'][$i]['password'] = 'password';

/* End of servers configuration */
$cfg['blowfish_secret'] = 'a random string';
$cfg['DefaultLang'] = 'en';
$cfg['ServerDefault'] = 0;
$cfg['UploadDir'] = '';
$cfg['SaveDir'] = '';

Now you can copy the file to /etc/phpmyadmin/

SSH tunneling

If you have mysql server running on your box stop it using

1
sudo service mysql stop

Once done connect and tunnel through ssh with

1
ssh -L 3306:localhost:3306 user@host

You should now be able to access to your DBs with PhpMyAdmin…