GoAdmio

clearsession

Delete all PHP session files on the server, logging out every site visitor

On this page: Overview · Quick start · Syntax · Output · Examples · Troubleshooting · Details · See also


Overview

/go/clearsession deletes every PHP session file on the server. Sites that keep their login or cart data in PHP sessions lose it, so visitors are logged out and must sign in again.

It first runs session to make sure the session directories exist with the right permissions, then empties them.


Quick start

# Delete all PHP session files
/go/clearsession

[!WARNING] This signs out every user of every site that stores sessions in these folders, including administrators, and empties shopping carts and unsaved form data. It runs immediately, with no confirmation and no way to undo it. To delete only old sessions, use clean.


Syntax

/go/clearsession

The command takes no options or arguments. Any you pass are ignored.


Output

The command prints nothing. Unlike most GoAdmio commands, it doesn't write to a log file in /var/log/go/.

It doesn't re-run itself as root. Each step is run with sudo, so the account you use must be able to run sudo without being blocked.


Examples

# Clear all sessions, for example after a security incident or a session-related PHP bug
/go/clearsession
# Check how many session files exist before clearing
ls /var/lib/*/session | wc -l

Troubleshooting

Symptom Likely cause Fix
Users are still logged in after running The site keeps sessions elsewhere, such as Redis, Memcached, a database, or a custom session.save_path. Clear sessions in that store, or change the site's session settings.
Users were logged out unexpectedly The command ran, either manually or from a cron job. Don't schedule it. Use clean, which removes only sessions older than 3 days.
Session files reappear immediately Visitors are active and PHP created new sessions. Normal. Only existing files are deleted.
The command asks for a password You aren't root and sudo needs one. Run it as root, or from an account with passwordless sudo.

Details

What it does

  1. Runs session, which creates the PHP session directories and sets their permissions.
  2. Deletes everything inside every folder named session one level below /var/lib (the pattern /var/lib/*/session/*).

The session folders themselves are kept. Only their contents are removed, including any subfolders. The command doesn't restart PHP-FPM or the web server.

Compared with clean

Command Sessions deleted
clearsession All of them, regardless of age.
clean Only files older than 3 days, along with other cleanup tasks.

See also

Command Description
session Create and set permissions on PHP session directories
clean Delete old backups, trash, session files, and expired mail to free up disk space
cache Clear cached data files to free space and refresh state
sessioncookielifetime Read or set PHP session.cookie_lifetime across all php.ini files
sessiongcmaxlifetime Read or set PHP session.gc_maxlifetime across all php.ini files