Search code examples
phpubuntuphpmyadminlamp

phpMyAdmin 4.6 persistent login


Is there a way to stay logged-in forever in phpMyAdmin 4.6?

Previous versions were straightforward to edit but this one has multiple configuration files spread across multiple folders in Ubuntu.

I would like to have it like that in my VirtualBox, so security is not a concern here.


Solution

  • If you're logging in as the same user and don't need to have multiple user accounts, it could be that changing to the 'config' authentication type would be best for you.

    auth_type config

    It sounds like you're using the Ubuntu packaged version (or the phpMyAdmin PPA), in which case the main configuration file is /etc/phpmyadmin/config.inc.php. Other files are included from there for things like the blowfish secret key that are set automatically on install and don't usually need to be managed manually. You can edit that file and look for a line like

    $cfg['Servers'][$i]['auth_type'] = 'cookie';

    and change it to

    $cfg['Servers'][$i]['auth_type'] = 'config';

    If the line doesn't exist, just add the config line (the default is cookie), so it might not be set by Ubuntu.

    You'll also need to add the username and password as hardcoded values in the configuration:

    $cfg['Servers'][$i]['user'] = 'root';
    $cfg['Servers'][$i]['password'] = 'yourPassword';
    

    Of course, if you have a user other than root, you would use that username there, and substitute out your password in the appropriate spot as well.

    Extending cookie expiration

    If that's not appealing to you, you'll have to increase the time before the cookie session expires. Because PHP does some garbage collection and removes old sessions, you'll have to tell both phpMyAdmin and PHP to allow extra time. The phpMyAdmin setting is called LoginCookieValidty and the PHP setting is session.gc_maxlifetime

    In /etc/phpmyadmin/config.inc.php, you'll have to add another line. I don't know if there's an upper limit on this, (comments here conflictingly suggest either 65535 or something higher, where as this question shows a value of 200000). You could try setting it to, for instance, 5 years, and see what happens (or some lower, more sane, value):

    $cfg['LoginCookieValidity'] = 157680000;

    You'll also have to edit your PHP configuration file (if your Ubuntu installation is similar to my Debian one, it's probably /etc/php/7.4/apache2/php.ini, adjusted of course if you're not using Apache or have a different PHP version). Mine already has the default of

    session.gc_maxlifetime = 1440

    so you could change this to

    session.gc_maxlifetime = 157680000

    Note that the upper limit of both these values probably depends on your system architecture and some PHP limit that I can't find documented anywhere, so it might take some experimentation to find a high value that works correctly.