Increase the Session Timeout for phpMyAdmin


This post is in the category: Tips

Random small break-fix or enlightening ideas


I use phpMyAdmin a lot for LAMP development. The default login timeout is something like 30 minutes. Here is how to increase that.

The first file we need to edit is the phpMyAdmin configuration file – config.inc.php. The location of this file will vary depending on how this was installed. If phpMyAdmin was installed from the Ubuntu package repositories, it is located at /etc/phpmyadmin/config.inc.php.

Edit the file:

[root]$ vim /etc/phpmyadmin/config.inc.php

Add this line to the bottom (or edit it if the config option exists):

$cfg['LoginCookieValidity'] = 172800; /* 48 hours */

Change the timeout value to whatever your preference is.

After you update this setting, go ahead and log into phpMyAdmin again. You may see this message:

Your PHP parameter session.gc_maxlifetime is lower that cookie validity configured in phpMyAdmin, because of this, your login will expire sooner than configured in phpMyAdmin.

phpMyAdmin uses the PHP session cookie, and this also has a timeout value. To update this, we will need to update php.ini. Just like phpMyAdmin’s config file, the location will vary depending on your environment. If you installed PHP and Apache2 through Ubuntu’s repositories, the file in question is located at /etc/php5/apache2/php.ini.

So for me, I can edit the file by running this:

[root]$ vim /etc/php5/apache2/php.ini

Look for the option session.gc_maxlifetime. For me it was near line 1500. This is what I changed it to:

session.gc_maxlifetime = 172800

Keep in mind that if this value is too high on a busy server, you might start to hit memory or filesystem limits.

After saving this last file, restart Apache2:

[root]$ service apache2 restart

Now load phpMyAdmin again, and that warning should no longer appear.

This entry was posted in Tips on by .

About Andrew Wells

I have been developing on the LAMP stack since about 2006. I run Ubuntu XFCE on my desktop and have a history of managing Ubuntu and CentOS servers. I code web applications mostly in PHP but have experience with other languages as well. When I'm not working, I can be found working in my home lab or out snowboarding, hiking, camping, or biking depending on the season.

Leave a Reply

Your email address will not be published. Required fields are marked *