Search My Techie Guy

Wednesday, August 13, 2014

PHP Warning: date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting

Problem:
I was getting this warning in my cacti log whenever i would run the poller.php script in my cacti installation.
And my cacti graphs had the wrong time (i.e. my graphs were 2 hours behind my current time).

"PHP Warning:  strtotime(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in /var/www/html/cacti/include/global_constants.php on line 167"

PHP warning: date()
Solution:

1.  Find the php.ini file

# find / -name php.ini
/etc/php.ini
#

2. Edit this parameter to fit your timezone

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

3. You can get your system timezone from this file

# more /etc/sysconfig/clock 
ZONE="Africa/Kampala"
#

4. Restart Apache

# /etc/init.d/httpd restart

5. The warning should stop and your graphs should show the correct time.

No comments: