Default Timezone for all CLI/FPM/CGI PHP

Hi, all!
How do I set my default PHP Timezone (Europe/Rome) so that all CLI/FPM use it unless I change it as needed?

SYSTEM INFORMATION
OS type and version Ubuntu Linux 20.04.6
Virtualmin version 7.9.0

Have you tried setting timezone for the server (in webmin), I guess php would follow that, not 100% sure.

shows in my php

Thanks for your reply; yes… It is set to Europe/Rome… :expressionless:

What sounds weird is that on my virtualhost I manually set PHP FPM to Europe/Rome and the web application recognize it…
When I run cronjobs with php on the same virtualhost/user it seems the setting is not considered as per the following php -i results…

date

date/time support => enabled
timelib version => 2022.10
"Olson" Timezone Database Version => 0.system
Timezone Database => internal
Default timezone => UTC

Directive => Local Value => Master Value
date.default_latitude => 31.7667 => 31.7667
date.default_longitude => 35.2333 => 35.2333
date.sunrise_zenith => 90.833333 => 90.833333
date.sunset_zenith => 90.833333 => 90.833333
date.timezone => UTC => UTC

To obtain the correct directive I tried setting timezone in the relevant CLI setting…

date

date/time support => enabled
timelib version => 2022.10
"Olson" Timezone Database Version => 0.system
Timezone Database => internal
Default timezone => Europe/Rome

Directive => Local Value => Master Value
date.default_latitude => 31.7667 => 31.7667
date.default_longitude => 35.2333 => 35.2333
date.sunrise_zenith => 90.833333 => 90.833333
date.sunset_zenith => 90.833333 => 90.833333
date.timezone => Europe/Rome => Europe/Rome

But this means I should always check all FPM versions settings…?

It would be great to set a default, as you mentioned, and have it everywhere unless set with a different value…

I tend to ignore that and add a line to the code just after the opening php tag & change it on the fly

<?php
date_default_timezone_set('Europe/Rome');
// your code starts here 

given that you could read the required timezone from an ini/settings file and change it there rather than editing the source code each time you want to ‘move’ time zones. This then works with whichever mode of PHP the file is invoked by.
– EDIT –
but what is the output from

timedatectl | head -4 | tail -1

Also setting timezone in the relevant CLI setting did not solve my problems with cron jobs, anyway…
I set my cron job with php -d date.timezone=“Europe/Rome” /public_html/cron.php and this fixed my application’s (GLPI) issues with cron based timestamps…

Where should it be run?

from a terminal, from webmin/virtualmin click the arrowed item & run it there
image

I’ve never set that and the phpinfo shows Australia. what sort of web application are you talking about.

timedatectl | head -4 | tail -1
Failed to create bus connection: No such file or directory

The application is GLPI - Its web interface woks fine with that timezone settings on its virtual host…
The problem was with its cron job / that seemed keeping working as on UTC…
Now fixed with that workaround on cron…

1 Like

restart the dbus service that has failed

service dbus restart

root@myhostname:~# service dbus restart
Failed to restart dbus.service: Operation refused, unit dbus.service may be requested by dependency only (it is configured to refuse manual start/stop).
See system logs and 'systemctl status dbus.service' for details.
root@myhostname:~# systemctl status dbus.service
● dbus.service - D-Bus System Message Bus
     Loaded: loaded (/lib/systemd/system/dbus.service; static; vendor preset: enabled)
     Active: inactive (dead)
TriggeredBy: ● dbus.socket
       Docs: man:dbus-daemon(1)

Thanks!

Rebooted…

root@myhostname:~# timedatectl | head -4 | tail -1
                Time zone: Europe/Rome (CET, +0100)

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.