PHP 5.4 Timezone Error Message on Ubuntu

Quick post because this tripped me up the other day: When you use a vanilla ubuntu 12.10 "Quantal Quetzal" installation, it will come with PHP 5.4, which is excellent news. However the default php.ini doesn't set the timezone, so you will see an error like:

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.

These have been warnings in earlier versions of PHP, but as of PHP 5.4, the date.timezone ini setting must be set correctly, using the continent and place - for me that's "Europe/London", like this:

date.timezone = "Europe/London"

If you see these errors, don't panic, just add the line above to your php.ini.

5 thoughts on “PHP 5.4 Timezone Error Message on Ubuntu

  1. I'm not sure for what this post is :) The error message exactly says what developer need to do, to fix this issue.

  2. I thought you meant a fatal error, I had to double check it. It's an E_WARNING. date.timezone will actually fall back to UTC if you *don't* set it, this is important because that can cause unepected results.

    "PHP will no longer attempt to guess the timezone, and will instead fall back to "UTC" and issue a E_WARNING." http://php.net/ChangeLog-5.php#5.4.0

    • How right you are! It's a fatal error because I'm using a DateTime() object, and then not catching the Exception it throws when the timezone isn't set. So I see a fatal error but I think other code might just see a warning. The fix is the same in either case, and has been the recommended setup for a couple of versions I think, but isn't there by default on a vanilla Ubuntu 12.10 installation.

Leave a Reply

Please use [code] and [/code] around any source code you wish to share.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>