Date and time not working

Having a problem where my date and time aren’t working when doing php.
[FAIL] You have a different system timezone (UTC) than the php configured timezone (EDT)
[FIX] Please correct either your system timezone or your timezone set in php.ini.

But my files look like:
/etc/php/7.0/apache2/php.ini

[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = "America/New_York"

/etc/php/7.0/cli/php.ini

[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = "America/New_York"

What the error is saying is that you have different timezones configured in system and php.

Or you change your system timezone or your php timezone, but should be the same.

my current system timezone is Eastern New York time though? I’m not quite sure understand why this error persists.

post output cat /etc/timezone

Hi,
I’m having the same issue.

[email protected]:/opt/librenms# date
Thu Sep 20 10:16:36 CEST 2018
[email protected]:/opt/librenms# cat /etc/timezone
Europe/Warsaw
[email protected]:/opt/librenms# grep -R “timezone” /etc/php/7.2/apache2/php.ini
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = Europe/Warsaw
[email protected]:/opt/librenms# grep -R “timezone” /etc/php/7.2/cli/php.ini
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = Europe/Warsaw
[email protected]:/opt/librenms#

Time on alerts is being displayed in UTC (2 hours earlier) even though PHP time is set to UTC+2 (Warsaw)

phpinfo();

System Linux xx 4.15.0-34-generic #37-Ubuntu SMP Mon Aug 27 15:21:48 UTC 2018 x86_64
Build Date Sep 13 2018 13:45:02
Server API Apache 2.0 Handler
Virtual Directory Support disabled
Configuration File (php.ini) Path /etc/php/7.2/apache2
Loaded Configuration File /etc/php/7.2/apache2/php.ini
Scan this dir for additional .ini files /etc/php/7.2/apache2/conf.d
Additional .ini files parsed /etc/php/7.2/apache2/conf.d/10-mysqlnd.ini, /etc/php/7.2/apache2/conf.d/10-opcache.ini, /etc/php/7.2/apache2/conf.d/10-pdo.ini, /etc/php/7.2/apache2/conf.d/15-xml.ini, /etc/php/7.2/apache2/conf.d/20-calendar.ini, /etc/php/7.2/apache2/conf.d/20-ctype.ini, /etc/php/7.2/apache2/conf.d/20-curl.ini, /etc/php/7.2/apache2/conf.d/20-dom.ini, /etc/php/7.2/apache2/conf.d/20-exif.ini, /etc/php/7.2/apache2/conf.d/20-fileinfo.ini, /etc/php/7.2/apache2/conf.d/20-ftp.ini, /etc/php/7.2/apache2/conf.d/20-gd.ini, /etc/php/7.2/apache2/conf.d/20-gettext.ini, /etc/php/7.2/apache2/conf.d/20-iconv.ini, /etc/php/7.2/apache2/conf.d/20-json.ini, /etc/php/7.2/apache2/conf.d/20-mbstring.ini, /etc/php/7.2/apache2/conf.d/20-mysqli.ini, /etc/php/7.2/apache2/conf.d/20-pdo_mysql.ini, /etc/php/7.2/apache2/conf.d/20-phar.ini, /etc/php/7.2/apache2/conf.d/20-posix.ini, /etc/php/7.2/apache2/conf.d/20-readline.ini, /etc/php/7.2/apache2/conf.d/20-shmop.ini, /etc/php/7.2/apache2/conf.d/20-simplexml.ini, /etc/php/7.2/apache2/conf.d/20-snmp.ini, /etc/php/7.2/apache2/conf.d/20-sockets.ini, /etc/php/7.2/apache2/conf.d/20-sysvmsg.ini, /etc/php/7.2/apache2/conf.d/20-sysvsem.ini, /etc/php/7.2/apache2/conf.d/20-sysvshm.ini, /etc/php/7.2/apache2/conf.d/20-tokenizer.ini, /etc/php/7.2/apache2/conf.d/20-wddx.ini, /etc/php/7.2/apache2/conf.d/20-xmlreader.ini, /etc/php/7.2/apache2/conf.d/20-xmlwriter.ini, /etc/php/7.2/apache2/conf.d/20-xsl.ini, /etc/php/7.2/apache2/conf.d/20-zip.ini
PHP API 20170718
PHP Extension 20170718
Zend Extension 320170718
Zend Extension Build API320170718,NTS
PHP Extension Build API20170718,NTS
Debug Build no
Thread Safety disabled
Zend Signal Handling enabled
Zend Memory Manager enabled
Zend Multibyte Support provided by mbstring
IPv6 Support enabled
DTrace Support available, disabled
Registered PHP Streams https, ftps, compress.zlib, php, file, glob, data, http, ftp, phar, zip
Registered Stream Socket Transports tcp, udp, unix, udg, ssl, tls, tlsv1.0, tlsv1.1, tlsv1.2
Registered Stream Filters zlib., string.rot13, string.toupper, string.tolower, string.strip_tags, convert., consumed, dechunk, convert.iconv.*

(…)

date

date/time support enabled
timelib version 2017.06
“Olson” Timezone Database Version 0.system
Timezone Database internal
Default timezone Europe/Warsaw

(…)

[email protected]:/opt/librenms# dpkg -l | grep -i php
ii composer 1.6.3-1 all dependency manager for PHP
ii libapache2-mod-php7.2 7.2.10-0ubuntu0.18.04.1 amd64 server-side, HTML-embedded scripting language (Apache 2 module)
ii php-cli-prompt 1.0.3+dfsg-1 all tiny helper prompting for user input
ii php-common 1:60ubuntu1 all Common files for PHP packages
ii php-composer-ca-bundle 1.1.0-1 all utility library to find a path to the system CA bundle
ii php-composer-semver 1.4.2-1 all utilities, version constraint parsing and validation
ii php-composer-spdx-licenses 1.3.0-1 all SPDX licenses list and validation library
ii php-json-schema 5.2.6-1 all implementation of JSON schema
ii php-psr-log 1.0.2-1 all common interface for logging libraries
ii php-symfony-console 3.4.6+dfsg-1ubuntu0.1 all run tasks from the command line
ii php-symfony-debug 3.4.6+dfsg-1ubuntu0.1 all tools to make debugging of PHP code easier
ii php-symfony-filesystem 3.4.6+dfsg-1ubuntu0.1 all basic filesystem utilities
ii php-symfony-finder 3.4.6+dfsg-1ubuntu0.1 all find files and directories
ii php-symfony-polyfill-mbstring 1.6.0-2 all Symfony polyfill for the Mbstring extension
ii php-symfony-process 3.4.6+dfsg-1ubuntu0.1 all execute commands in sub-processes
ii php7.2-cli 7.2.10-0ubuntu0.18.04.1 amd64 command-line interpreter for the PHP scripting language
ii php7.2-common 7.2.10-0ubuntu0.18.04.1 amd64 documentation, examples and common module for PHP
ii php7.2-curl 7.2.10-0ubuntu0.18.04.1 amd64 CURL module for PHP
ii php7.2-gd 7.2.10-0ubuntu0.18.04.1 amd64 GD module for PHP
ii php7.2-json 7.2.10-0ubuntu0.18.04.1 amd64 JSON module for PHP
ii php7.2-mbstring 7.2.10-0ubuntu0.18.04.1 amd64 MBSTRING module for PHP
ii php7.2-mysql 7.2.10-0ubuntu0.18.04.1 amd64 MySQL module for PHP
ii php7.2-opcache 7.2.10-0ubuntu0.18.04.1 amd64 Zend OpCache module for PHP
ii php7.2-readline 7.2.10-0ubuntu0.18.04.1 amd64 readline module for PHP
ii php7.2-snmp 7.2.10-0ubuntu0.18.04.1 amd64 SNMP module for PHP
ii php7.2-xml 7.2.10-0ubuntu0.18.04.1 amd64 DOM, SimpleXML, WDDX, XML, and XSL module for PHP
ii php7.2-zip 7.2.10-0ubuntu0.18.04.1 amd64 Zip module for PHP

[email protected]:/opt/librenms# ./validate.php

Component Version
LibreNMS 1.43-100-gfc12175ee
DB Schema 267
PHP 7.2.10-0ubuntu0.18.04.1
MySQL 10.1.34-MariaDB-0ubuntu0.18.04.1
RRDTool 1.7.0
SNMP NET-SNMP 5.7.3

====================================

[OK] Composer Version: 1.7.2
[OK] Dependencies up-to-date.
[OK] Database connection successful
[OK] Database schema correct
[WARN] Your local git contains modified files, this could prevent automatic updates.
[FIX] You can fix this with ./scripts/github-remove
Modified Files:
bootstrap/cache/.gitignore
includes/functions.php
storage/app/.gitignore
storage/app/public/.gitignore
storage/debugbar/.gitignore
storage/framework/cache/.gitignore
storage/framework/sessions/.gitignore
storage/framework/testing/.gitignore
storage/framework/views/.gitignore
storage/logs/.gitignore

Do you, by any chance, have your database in other server?

Same server.

cat config.php
<?php
## Have a look in defaults.inc.php for examples of settings you can set here. DO NOT EDIT defaults.inc.php!

### Database config
$config['db_host'] = 'localhost';
$config['db_port'] = '3306';
$config['db_user'] = 'librenms';
$config['db_pass'] = 'XXXXXX';
$config['db_name'] = 'librenms';
$config['db_socket'] = '';

// This is the user LibreNMS will run as
//Please ensure this user is created and has the correct permissions to your install
$config['user'] = 'librenms';

### Locations - it is recommended to keep the default
#$config['install_dir']  = "/opt/librenms";

### This should *only* be set if you want to *force* a particular hostname/port
### It will prevent the web interface being usable form any other hostname
#$config['base_url']        = "http://librenms.company.com";

### Enable this to use rrdcached. Be sure rrd_dir is within the rrdcached dir
### and that your web server has permission to talk to rrdcached.
#$config['rrdcached']    = "unix:/var/run/rrdcached.sock";

### Default community
$config['snmp']['community'] = array("public");

### Authentication Model
$config['auth_mechanism'] = "mysql"; # default, other options: ldap, http-auth
#$config['http_auth_guest'] = "guest"; # remember to configure this user if you use http-auth

### List of RFC1918 networks to allow scanning-based discovery
#$config['nets'][] = "10.0.0.0/8";
#$config['nets'][] = "172.16.0.0/12";
#$config['nets'][] = "192.168.0.0/16";

# Update configuration
#$config['update_channel'] = 'release';  # uncomment to follow the monthly release channel
#$config['update'] = 0;  # uncomment to completely disable updates

Any ideas guys? It’s a fresh install of ubuntu 18.04, time on the server is fine so I don’t know where is this coming from.
I dont’ know what else I can check.

As a test you could temporarily alter
config/app.php

line:

'timezone' => ini_get('date.timezone') ?: 'UTC', // use existing timezone

to

'timezone' => ini_get('date.timezone') ?: 'Europe/Warsaw', // use existing timezone

It didn’t help.
Whats curious is that poller log is displaying correct time, while alerts and eventlog in the GUI is displaying wrong time.

/opt/librenms/poller.php 19 2018-09-27 11:20:09 - 1 devices polled in 2.173 secs
/opt/librenms/poller.php 5 2018-09-27 11:20:10 - 1 devices polled in 3.802 secs
/opt/librenms/poller.php 10 2018-09-27 11:20:15 - 1 devices polled in 2.080 secs
/opt/librenms/poller.php 7 2018-09-27 11:20:16 - 1 devices polled in 1.896 secs


|2018-09-27 09:17:02|alert|[192.168.xx.205](http://nms.xx/device/device=5/)|Issued critical alert for rule 'Devices up/down' to transport 'mail'|System|
| --- | --- | --- | --- | --- |
|2018-09-27 09:17:02|alert|[192.168.xx205](http://nms.xx/device/device=5/)|Issued critical alert for rule 'Devices up/down' to transport 'api'|System|
|2018-09-27 09:16:02|alert|[192.168.xx.205](http://nms.xx/device/device=5/)|Issued critical alert for rule 'Devices up/down' to transport 'mail'|System|
|2018-09-27 09:16:02|alert|[192.168.xx.205](http://nms.xx/device/device=5/)|Issued critical alert for rule 'Devices up/down' to transport 'api'|

perhaps check your DB default-time-zone,

Check current db clock

SELECT NOW();
SELECT @@global.time_zone;

then check config
/etc/my.cnf

default-time-zone='Europe/Warsaw'

https://dev.mysql.com/doc/refman/5.5/en/time-zone-support.html

You might need to restart

So, when I was checking your
select now();
it was wrong, I tried putting the config option to various files but mysql daemon always failed to start so in the end I didn’t add default-time-zone to sql settings.

What’s interesting, now it works and I am unsure what helped here.
I reverted config/app.php, rebooted the whole server and it is still working.

I saw somewhere that a restart of mysql forces sync of system time, maybe after time zone is changed a restart is required so now everything is good :sunglasses:

Makes sense.
Thank you for all the help.