Error: PHP - It is not safe to rely on the system's timezone settings.

You get the following warning when you run a PHP script:

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.

 

Solution

First find out your system's timezone. On Debian/Ubuntu, it's in /etc/timezone:

cat /etc/timezone

[email protected]:~# cat /etc/timezone
Europe/Berlin
[email protected]:~#

On Fedora/CentOS/RedHat, it's in /etc/sysconfig/clock:

cat /etc/sysconfig/clock

[[email protected] ~]# cat /etc/sysconfig/clock
ZONE="Europe/Berlin"
UTC=true
ARC=false
[[email protected] ~]#

Open your php.ini. On Debian/Ubuntu, it's /etc/php5/apache2/php.ini:

vi /etc/php5/apache2/php.ini

On Fedora/CentOS/RedHat, it's /etc/php.ini:

vi /etc/php.ini

Find the date.timezone line, make sure it is not commented out and has the correct timezone for your system:

date.timezone="Europe/Berlin"

Restart Apache afterwards:

On Debian/Ubuntu, you run:

/etc/init.d/apache2 restart

On Fedora/CentOS/RedHat, you run:

/etc/init.d/httpd restart

If you don't have access to your system's php.ini, you can set the default timezone at the beginning of your PHP scripts as follows:

<?php
date_default_timezone_set("Europe/Berlin");
[...]
?>
Falko Timme

About Falko Timme

Falko Timme is an experienced Linux administrator and founder of Timme Hosting, a leading nginx business hosting company in Germany. He is one of the most active authors on HowtoForge since 2005 and one of the core developers of ISPConfig since 2000. He has also contributed to the O'Reilly book "Linux System Administration".

Share this page:

Suggested articles

2 Comment(s)

Add comment

Comments

By: denuxer

i have loaded date.timezon on php.ini file and on /etc/timzone

but not fix the problem, untiil i have to check the php configuration file i use following: php -i | grep php.ini | tail -n2

and it show the miss configuration i have.

By: Php Web Developer

Great tutorial. This tutorial was really useful to set default timezone in php.

Thanks.