Home / Set the default font size for phpMyAdmin

Set the default font size for phpMyAdmin

phpMyAdmin is a web based administrative tool for the MySQL database server. After logging in to phpMyAdmin there’s a drop down box to select the font size as a percentage which always defaults to 100% and is too big for my liking. After changing the value, the font size is remembered as a cookie so the next time you log in the font size chosen is remembered. However the font size cookie drops off eventually and when logging into a phpMyAdmin that I haven’t logged into for a while I find it annoying having to change the font size each time. This post looks at how to change the default phpMyAdmin font size.

This post was written using phpMyAdmin 2.10.0.1 to change the settings and look at the issues involved. The information here may not apply to older or more recent versions of phpMyAdmin.

phpMyAdmin has two configuration files that it uses each time it runs. The first contains the default configuration settings and is stored at libraries/config.default.php and you would not normally modify this file at all. The second contains your own specific settings and effectively overrides the settings in the default file. This is stored in the phpMyAdmin root directory and is called config.inc.php

Note: when you first set up phpMyAdmin the config.inc.php file is not present and you need to copy the config.sample.inc.php and then customise to suit.

There is a configuration option called ‘fontsize’ which is what is supposed to be used for setting the default font size. The function which determines the font size to use looks like this (from libraries/Config.class.php):

function checkFontsize()
{
    $new_fontsize = '';
     if (isset($_GET['fontsize'])) {
        $new_fontsize = $_GET['fontsize'];
    } elseif (isset($_POST['fontsize'])) {
        $new_fontsize = $_POST['fontsize'];
    } elseif (isset($_COOKIE['pma_fontsize'])) {
        $new_fontsize = $_COOKIE['pma_fontsize'];
    }

    if (preg_match('/^[0-9.]+(px|em|pt|%)$/', $new_fontsize)) {
        $this->set('fontsize', $new_fontsize);
     } elseif (! $this->get('fontsize')) {
        $this->set('fontsize', '100%');
    }

    if (function_exists('PMA_setCookie')) {
        PMA_setCookie('pma_fontsize', $this->get('fontsize'), '100%');
    }
}

As you can see the order of preference is to get the font size value from $_GET, then $_POST (if $_GET does not have it), then $_COOKIE (if $_POST does not have it), then from the configuration, and then default to 100% if it’s not stored in the configuration.

So it should just be a matter of adding the following to the config.inc.php file, clearing your cookies and reloading phpMyAdmin to get the default font size of e.g. 80%:

$cfg['fontsize'] = '80%';

I tested the checkFontSize() code and it does correctly read the 80% value from the configuration and return it, but somewhere else it seems to revert it back to 100% although I couldn’t manage to work out where. After reading further through the code I discovered that the default configuration is also loaded at some stage and decided to test adding the above line to it. The default configuration file (at libraries/config.default.php) doesn’t contain a fontsize setting, so just add the above to the end. And then it will use that value as the default font size.

Summary

To change the default font size in phpMyAdmin you would expect to add the fontsize value to your config.inc.php file but it appears to be ignored. Although you probably shouldn’t edit the default configuration file, adding the font size value to the libraries/config.default.php file works.