Skip to content

phpMyAdmin session timeout: LoginCookieValidity, session.gc_maxlifetime, and the mtime trap

Two clocks end a phpMyAdmin session: phpMyAdmin's own idle timer and PHP's garbage collector, which judges the session file by its modification time. Raising one without the other changes nothing. The mechanism, the shared save_path trap, and where the config actually lives on cPanel.

Two independent clocks can end a phpMyAdmin session, and the one people adjust is usually not the one that fired. phpMyAdmin keeps its own idle timer — $cfg['LoginCookieValidity'], 1440 seconds by default — and signs you out with Your session has expired. Please log in again. once the gap since your last recorded access exceeds it. Underneath that, PHP’s session garbage collector deletes the session file when the file’s modification time is older than session.gc_maxlifetime, also 1440 by default. When the file goes, phpMyAdmin has nothing left to read and the login is over regardless of what its own timer said. That is why raising one setting alone changes nothing. The detail that makes the behaviour genuinely hard to predict is the mtime part: PHP only rewrites the session file when the session data changes, so a session file can age past its lifetime while you are still clicking around.

What you’ll accomplish

  • Tell apart the two layers that expire a phpMyAdmin session, and read which one killed yours from the evidence on disk.
  • Understand why session.gc_maxlifetime is measured against a file mtime that does not always advance with your activity.
  • Find out whether you are on cPanel’s bundled phpMyAdmin or a self-hosted copy, because the config file and the PHP that reads it are completely different.
  • Raise both layers together for the duration of a task, verify the change took effect, and put it back.
  • Recognise the cases where a longer browser session is the wrong tool entirely.

Prerequisites

  • Root SSH on the server if you are touching cPanel’s bundled phpMyAdmin, or cPanel-level file access if it is a copy installed in your own docroot.
  • Knowing which PHP serves the page. cPanel’s bundled phpMyAdmin runs under cPanel’s own internal PHP through cpsrvd, not under the account’s EasyApache PHP. This single fact invalidates most of the advice you will find on forums.
  • An honest note on OS differences. PHP’s session garbage collection is probabilistic — it fires on session_start() with odds of session.gc_probability / session.gc_divisor. Debian and Ubuntu packages set session.gc_probability = 0 and sweep sessions from a system timer instead; Enterprise Linux family packages (AlmaLinux, Rocky, RHEL) generally leave the in-process GC enabled. Do not assume — read the values on the box.
  • A maintenance window if you will restart cpsrvd. That restart ends every active cPanel, WHM and Webmail session on the server, including your own.

How it works

Layer 1 is phpMyAdmin’s. On login it records an access timestamp inside the session, refreshes it as you work, and compares the gap against $cfg['LoginCookieValidity']. Exceed it and phpMyAdmin destroys the login itself. This is the layer that produces the polite expiry message and the login form with your server and username still filled in.

Layer 2 is PHP’s, and phpMyAdmin has no visibility into it. With the default files save handler, each session lives as one file named sess_<id> inside session.save_path. When garbage collection runs, PHP scans that directory and unlinks every file whose mtime is older than session.gc_maxlifetime seconds. phpMyAdmin’s next request calls session_start(), finds no file, and treats you as an unauthenticated visitor. You get bounced to the login screen with no explanation, sometimes with an invalid token complaint on the way.

The mtime is where intuition breaks. PHP does not stamp the file on every request — since PHP 7.0 the session.lazy_write directive is on by default, and the files handler skips the write entirely when the serialised session data is byte-identical to what it read. A request that only reads the session leaves the mtime exactly where it was. Whether a given phpMyAdmin page changes session data depends on what that page does, so the file can quietly age past gc_maxlifetime during a stretch of browsing that felt like continuous use. Layer 1 sees an active user. Layer 2 sees a stale file. Layer 2 wins.

Timeline showing phpMyAdmin's LoginCookieValidity timer resetting on every request while the PHP session file mtime advances only when session data changes, so garbage collection deletes the file first

Two more things ride on top of this. The GC scan is not scoped to your application: it walks the whole session.save_path directory. On a default distro layout every PHP application on the host shares /tmp, /var/tmp or a single /var/lib/php/sessions, and whichever co-tenant’s request happens to trigger the sweep applies its own gc_maxlifetime to everyone’s files. The shortest lifetime among the co-tenants effectively wins. And on cPanel specifically, a third clock exists above both: phpMyAdmin is reached through an authenticated cPanel session, so cpsrvd’s own idle timeout can log you out while both PHP layers are perfectly healthy.

Step-by-step

  1. Read the current values before changing anything. Run this against the PHP that actually serves your phpMyAdmin — see step 2 if you are unsure which that is.

    php -i | grep -E 'session.gc_maxlifetime|session.gc_probability|session.gc_divisor|session.save_path|session.lazy_write'

    A Debian or Ubuntu host answers roughly like this:

    session.gc_divisor => 1000 => 1000
    session.gc_maxlifetime => 1440 => 1440
    session.gc_probability => 0 => 0
    session.lazy_write => On => On
    session.save_path => /var/lib/php/sessions => /var/lib/php/sessions

    gc_probability => 0 means the in-process collector never runs and a system timer does the sweeping instead. On EL-family packages you will typically see session.gc_probability => 1 and the sweep happening inside random requests. Either way, expiry is approximate — a file can outlive gc_maxlifetime until something triggers a scan.

  2. Establish which phpMyAdmin you are on. This decides every path that follows.

    Decision map branching between cPanel's bundled phpMyAdmin served by cpsrvd under cPanel's internal PHP and a self-hosted copy in an account docroot served by EasyApache PHP, with the config file paths on each branch

    If you reach it from inside cPanel’s Databases section on port 2083, it is cPanel’s bundled copy:

    ls -l /usr/local/cpanel/base/3rdparty/phpMyAdmin/config.inc.php
    /usr/local/cpanel/3rdparty/bin/php -i | grep -E 'session.gc_maxlifetime|session.save_path'

    If you installed phpMyAdmin yourself into a docroot such as /home/USER/public_html/pma/, it is served by the account’s EasyApache PHP and the ordinary account tooling applies.

  3. On the bundled copy, back up first and understand what you are agreeing to. Everything under /usr/local/cpanel/ belongs to cPanel’s updater and is replaced on every update, so any edit here is temporary by design — it will silently revert, usually at the worst moment.

    cp -a /usr/local/cpanel/base/3rdparty/phpMyAdmin/config.inc.php \
      /root/pma-config.inc.php.bak-$(date +%F)
    -rw-r--r-- 1 root root 3218 Aug 18 09:12 /root/pma-config.inc.php.bak-2026-08-18

    Then add or edit the directive in config.inc.php:

    $cfg['LoginCookieValidity'] = 7200;

    Editing the account’s php.ini, the .user.ini in a docroot, or MultiPHP INI Editor does not affect this copy. Those configure EasyApache PHP; the bundled phpMyAdmin never reads them.

  4. Match PHP’s lifetime to it, on the same PHP. For the bundled copy the relevant ini is cPanel’s internal one:

    grep -n 'session.gc_maxlifetime' /usr/local/cpanel/3rdparty/etc/php.ini

    Set it to at least the value from step 3. phpMyAdmin itself checks this relationship and shows a configuration warning when LoginCookieValidity exceeds session.gc_maxlifetime, which is a useful confirmation that you got the pairing right.

  5. On a self-hosted copy, use the account-level route instead. Set phpMyAdmin’s own value in the installation’s config.inc.php, and PHP’s in .user.ini at the docroot (PHP-FPM and CGI/FastCGI handlers read it; session.gc_maxlifetime and session.save_path are both settable there):

    session.gc_maxlifetime = 7200
    session.save_path = "/home/USER/tmp/phpsessions"

    A per-account session.save_path is the fix for the shared-directory problem — your files are no longer in the same directory another application’s GC sweeps. Create it with the account’s ownership and keep it out of the web root. .user.ini is cached, so the change lands after user_ini.cache_ttl seconds (300 by default) rather than instantly.

  6. Apply it, knowing what the restart costs. config.inc.php takes effect on the next page load. An ini change for cPanel’s internal PHP needs cpsrvd restarted:

    /scripts/restartsrv_cpsrvd

    This drops every active cPanel, WHM and Webmail session on the server. Anyone mid-task loses it. Schedule accordingly, and if the restart misbehaves, restoring the backup from step 3 and restarting again returns you to the previous state.

Validate it works

Confirm PHP first, then phpMyAdmin, then the file on disk.

php -i | grep -E 'session.gc_maxlifetime|session.save_path|session.gc_probability'
session.gc_maxlifetime => 7200 => 7200
session.gc_probability => 0 => 0
session.save_path => /home/USER/tmp/phpsessions => /home/USER/tmp/phpsessions

Both columns matter: the first is the master value, the second the current effective one. If they disagree, something later in the load order is overriding you.

Now watch the mtime advance — or fail to. Log in, note the timestamp, click around for a few minutes, and look again:

stat -c '%n mtime=%y' /home/USER/tmp/phpsessions/sess_* ; date
/home/USER/tmp/phpsessions/sess_9f2c1ab4e7d80516 mtime=2026-08-18 09:41:07.219 -0400
Mon Aug 18 09:46:02 EDT 2026

A five-minute gap between mtime and now, while you were actively using the interface, is session.lazy_write doing exactly what it is documented to do — and it is the countdown that will end your session. Finally, confirm phpMyAdmin’s own value took by grepping the config it actually reads:

grep -n 'LoginCookieValidity' /usr/local/cpanel/base/3rdparty/phpMyAdmin/config.inc.php

Troubleshooting

  • You raised LoginCookieValidity and it still expires around 24 minutes. PHP’s GC is deleting the file first. gc_maxlifetime is still at 1440 on the PHP that serves the page — most often because you edited the account’s PHP configuration while cPanel’s bundled copy runs on cPanel’s internal PHP. Re-run the check in step 2 against /usr/local/cpanel/3rdparty/bin/php and compare.

  • Both values look right and sessions still die early. Check session.save_path. If it is a directory shared with other applications, another application’s sweep is applying its own shorter gc_maxlifetime to your files. Give the account its own save_path as in step 5. On Debian and Ubuntu, also check the system session-cleanup timer — it sweeps on the packaged lifetime independently of any per-site value.

  • The setting worked, then stopped after an update. Expected. Files under /usr/local/cpanel/ are replaced by cPanel updates. Compare against your backup, and treat this as the signal to move the work off the browser rather than re-applying the edit indefinitely.

  • The page dies at almost exactly 100 seconds, or 60. That is not a session timeout at all. Cloudflare’s proxy gives up on an origin that has not responded in 100 seconds and returns a 524; nginx in front of PHP-FPM defaults proxy_read_timeout to 60 seconds and returns a 504. Both cut a long-running query before either session layer is even consulted. The error page, not the login page, is the tell.

  • You came back to a suspended tab. Modern browsers discard background tabs to reclaim memory. The tab reloads on focus, that reload is the first request in a long time, and the session was collected in between. Nothing server-side is broken.

When this is the wrong approach

If the reason you want a longer session is a large import, a long export, or a query that takes half an hour, extending the browser session is treating the wrong problem. A browser round trip is the fragile part of that chain: it goes through a proxy timeout, a PHP max_execution_time, a session layer, and a tab that may be suspended. Run the work over SSH with mysql or mysqldump inside screen or tmux and none of those clocks apply — importing a large SQL file when phpMyAdmin times out covers that path, and finding and stopping long-running MySQL queries covers the case where the query itself is the problem.

There is also a security cost worth naming plainly. A phpMyAdmin session with full database rights, alive for hours on an unattended tab, is a standing credential on whatever machine that browser is running on — a shared workstation, a laptop in a café, a device someone else can reach. The defensible pattern is bounded: raise the values for the duration of a specific task, then put them back. Reverting is the same two edits with the original numbers, plus the same cpsrvd restart caveat. PHP’s session directives are documented in the PHP session configuration reference, and phpMyAdmin’s own settings in the phpMyAdmin documentation.

If this is the kind of work you’d rather never own again, it’s the daily job of Managed Cloud Ops — book an infrastructure review.