Timezone PHP and CRON

Hi there.
Server hwclock 2023-11-17 09:40:18.701982+02:00
My local time is 2023-11-17 09:40 Europe/Kyiv
I set it in settings timezone Europe/Kyiv

checked in
/etc/php/7.0/cli/php.ini - OK
/etc/php/7.0/cli/php.ini - OK

But:
php date(“Y-m-d H:i”) - 2023-11-17 08:40
And so that the cron runs at 10 o’clock in my local time, I set 8 hours in the cron (-2 hours)

How can I force PHP to output the default time of the installed zone?

And the cron would work according to my time.
I expect that by setting the start to 10 o’clock, I will get 10 o’clock in my local time.

It is very strange!
PHP return
date_default_timezone_get() = Europe/Berlin
ini_get(‘date.timezone’) = Europe/Berlin

Maybe your site or command line is not using php7.0 and it is using php8.x.

php -version

Check that you have the right timezone in all your php.ini files:

grep -r 'date\.timezone\s=' /etc/php/

Really! I’ll try to fix this.

/etc/php/8.2/cli/php.ini:date.timezone = Europe/Kyiv
/etc/php/8.2/cli/php.ini.vst.back:date.timezone = Europe/Berlin
/etc/php/8.2/fpm/php.ini:date.timezone = Europe/Kyiv
/etc/php/8.2/fpm/php.ini.vst.back:date.timezone = Europe/Berlin
/etc/php/7.4/cli/php.ini:date.timezone = Europe/Kyiv
/etc/php/7.4/cli/php.ini.vst.back:date.timezone = Europe/Berlin
/etc/php/7.4/fpm/php.ini:date.timezone = Europe/Kyiv
/etc/php/7.4/fpm/php.ini.vst.back:date.timezone = Europe/Berlin
/etc/php/7.1/cli/php.ini:date.timezone = Europe/Kyiv
/etc/php/7.1/cli/php.ini.vst.back:date.timezone = Europe/Berlin
/etc/php/7.1/fpm/php.ini:date.timezone = Europe/Kyiv
/etc/php/7.1/fpm/php.ini.vst.back:date.timezone = Europe/Berlin
/etc/php/8.0/cli/php.ini:date.timezone = Europe/Kyiv
/etc/php/8.0/cli/php.ini.vst.back:date.timezone = Europe/Berlin
/etc/php/8.0/fpm/php.ini:date.timezone = Europe/Kyiv
/etc/php/8.0/fpm/php.ini.vst.back:date.timezone = Europe/Berlin
/etc/php/7.0/cli/php.ini:date.timezone = Europe/Kyiv
/etc/php/7.0/cli/php.ini.vst.back:date.timezone = Europe/Berlin
/etc/php/7.0/fpm/php.ini:date.timezone = Europe/Kyiv
/etc/php/7.0/fpm/php.ini.vst.back:date.timezone = Europe/Berlin
/etc/php/7.2/cli/php.ini:date.timezone = Europe/Kyiv
/etc/php/7.2/cli/php.ini.vst.back:date.timezone = Europe/Berlin
/etc/php/7.2/fpm/php.ini:date.timezone = Europe/Kyiv
/etc/php/7.2/fpm/php.ini.vst.back:date.timezone = Europe/Berlin
/etc/php/7.3/cli/php.ini:date.timezone = Europe/Kyiv
/etc/php/7.3/cli/php.ini.vst.back:date.timezone = Europe/Berlin
/etc/php/7.3/fpm/php.ini:date.timezone = Europe/Kyiv
/etc/php/7.3/fpm/php.ini.vst.back:date.timezone = Europe/Berlin
/etc/php/8.1/cli/php.ini:date.timezone = Europe/Kyiv
/etc/php/8.1/cli/php.ini.vst.back:date.timezone = Europe/Berlin
/etc/php/8.1/fpm/php.ini:date.timezone = Europe/Kyiv
/etc/php/8.1/fpm/php.ini.vst.back:date.timezone = Europe/Berlin
/etc/php/5.6/cli/php.ini:date.timezone = Europe/Kyiv
/etc/php/5.6/cli/php.ini.vst.back:date.timezone = Europe/Berlin
/etc/php/5.6/fpm/php.ini:date.timezone = Europe/Kyiv
/etc/php/5.6/fpm/php.ini.vst.back:date.timezone = Europe/Berlin

Perhaps the server needs to be rebooted?

Yes, because Berlin is only in backup files. But no need to reboot, just restart php services but maybe reboot is faster :wink:

1 Like

Rebooted the server. Everything became fine. Tnx.

1 Like

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