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)