I just updated one of my CentOS systems to PHP 5.3 (a chore best reserved for another blog post), and started to see the following warning popping up:
PHP Notice: in file index.php on line 15: date(): 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 ‘America/Chicago’ for ‘CDT/-5.0/DST’ instead
Annoying to say the least. The fix is much easier than the message makes it seem.
PHP 5.3 now requires that you either have a timezone set in your php.ini file or that you pass the desired timezone via the date_default_timezone_set()
function before calling the date()
function.
I opened my server’s /etc/php.ini
file and searched for timezone. My ini file had a section like the following:
[Date] ; Defines the default timezone used by the date functions ; http://www.php.net/manual/en/datetime.configuration.php#ini.date.timezone ; date.timezone =
I uncommented the date.timezone
line and added the timezone I wanted.
[Date] ; Defines the default timezone used by the date functions ; http://www.php.net/manual/en/datetime.configuration.php#ini.date.timezone date.timezone = 'America/Chicago'
There are two very important things to do in order for this to work properly for you:
- Use a timezone that is appropriate for your needs. Use PHP’s List of Supported Timezones to find the timezone that works for you.
- Since your server is likely to cache the PHP configuration, you will want to restart your web server process in order for the change to be recognized. The command to execute varies by system, but for most systems, the following will work:
[user@server /etc]$ sudo service httpd restart [sudo] password for user: Stopping httpd: [ OK ] Starting httpd: [ OK ] [user@server /etc]$
Of course, if you are already root, you won’t need to use
sudo
:[root@server /etc]# service httpd restart Stopping httpd: [ OK ] Starting httpd: [ OK ] [root@server /etc]#
Did I help you?
Wow!!!! You safe my life. Thanks!!!!
Thanks so much for this Chris (as well as updating CentOS php from 5.1 to 5.3). You saved me so much time. Much appreciated!
Thank you Chris! It worked for me!
Another great post. Easy as pie! Thanks again.
Thanks a bunch for this tutorial! 🙂
[…] das was dir die Warnmeldung sagt es ist erforderlich das in php die timezone gesetzt wird -> PHP 5.3 and ?It is not safe to rely on the system?s timezone settings? :: Chris Jean Ask not what JTL-community can do for you – ask what you can do for JTL-community […]
Thank you Chris. This post really saved me
Thanks Chris, it’s worked. I’m using Codeiginiter and put the date_default_timezone_set() part in the controller’s parent function. I wonder how can you know this kind of solution?
I’m not familiar with CodeIgniter, so I don’t have any experience to offer. I did a quick search and found this solution. Perhaps it could be of help.
Thanks a lot