php settings in php.ini
:
date.timezone = Asia/Jerusalem.
My Linux server (Ubuntu) shows the correct time:
You solve it by setting the timezone explicitly in your PHP scripts. You can do this with date_default_timezone_set():
date_default_timezone_set('Asia/Jerusalem');
Here is the list of PHP supported timezones.
You may also want to try a test script calling date_default_timezone_get()
to see what it's actually set to to verify that this is in fact the problem.
List of Supported Timezones
Change the php timezone:
1) Open the php.ini file - vim /etc/php.ini
2) Change the default timezone settings by adding/modifying this line:
date.timezone = Asia/Jerusalem
- remove the ;
at the first of line (if exists)!
3) Save the php.ini file.
4) Restart the Apache server - systemctl restart httpd.service
.
The timezone settings should now be modified.
The Asia/Jerusalem timezone has daylight savings time currently in effect; it may be that php isn't handling this. The function call date('I')
will return 1
if your php is currently running DST, 0
otherwise.
Israel has undergone several changes to daylight saving time in the last few years. This year, DST is supposed to be in effect until October 26th. The last time the DST end date fell before October 1st was September 23, 2012. Reference here.
When Israel announced the changes for 2013 forward, they were released in the standard IANA time zone database in version 2013d. I actually answered a similar question back then, regarding how Java handles this change.
For PHP, the IANA database is implemented via the timezonedb PECL package. You can install this package manually to update to the latest version of the timezone data.
PHP also comes with a copy of timezonedb internally, which is supposed to be the most recent version available at the time that the PHP version is released. So simply upgrading PHP to the latest version should also solve the problem.
If you want to see what version of timezonedb you currently have (whether built-in, or updated) - you can call timezone_version_get()
, as documented here. It needs to be at least 2013.4 to have this particular change. The current release is 2014.7.
Set and check your time zone in php.
<?php
date_default_timezone_set('America/Los_Angeles'); // here set the time zone
$script_tz = date_default_timezone_get();
if (strcmp($script_tz, ini_get('date.timezone'))){
echo 'Script timezone differs from ini-set timezone.';
} else {
echo 'Script timezone and ini-set timezone match.';
}
?>