PHP session files persists for 1 week. How to change this?

SYSTEM INFORMATION
OS type and version Ubuntu 24.04
Virtualmin version 7.40.1

I’m noticing that php session files in the tmp directory persists for 1 week. For low traffic sites this is not a problem but for some of my sites this folder is taking up more than 20gb of data so I had to deal with this lately.

I started by looking at php’s garbage collector and found that its disabled by default. This is what I found in the php.ini file.

; https://php.net/session.gc-probability
; Debian Default Value: 0
; This is disabled in the Debian packages due to the strict permissions
; on /var/lib/php. Instead, GC is performed through /etc/cron.d/php,
; which uses the session.gc_maxlifetime setting. Please, check
; /usr/share/doc/php8.2-common/README.Debian.gz for further reference.
session.gc_probability = 0

Then I looked for the cron file. I found it and its set to run twice in an hour


I’m stumped now. How and where do I change this setting to clean up session more often than 1 week?

Every domain has its own PHP configuration, and that configuration location and format varies quite a bit based on execution mode, version, and where your PHP came from. Usually you’d want to edit your PHP configuration in Virtualmin. At the very least that will tell you what file to edit.

e.g. for PHP-FPM (the recommended execution mode on any current system).

Note that for PHP-FPM, I think you generally set config options with php_value[value_name] and php_admin_value[value_name] rather than using the php.ini syntax. Also note that shows you the path to the file, if you prefer to edit in a text editor. You’ll need root permissions to edit in an editor, though, and Virtualmin allows you to delegate it for domain owner configuration, if you want and trust your users to do that.

Do you want me to change the gc_probability setting? I was thinking we figure out how to make that cron file work as it seems that is the recommended way of doing session cleanup.