Fix PHP timezone warnings in OS X Snow Leopard

The standard Mac install of PHP has always been somewhat quirky, and 10.6 is no exception. One of the most obvious issues occurs when attempting to use date/time functions. PHP 5.3 requires that the date.timezone setting is available. Without this, you will receive a warning similar to the following:

Warning: getdate() [function.getdate]: 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 'Europe/London' for 'BST/1.0/DST' instead in /Users/gscott/Sites/hello-world.php on line 9

The solution is to edit (or create, if it doesn’t exist) /private/etc/php.ini and make sure a setting exists for date.timezone. For example:

date.timezone = Europe/London

After making the change, restart Apache

sudo apachectl restart

Glen Scott

I’m a freelance software developer with 18 years’ professional experience in web development. I specialise in creating tailor-made, web-based systems that can help your business run like clockwork. I am the Managing Director of Yellow Square Development.

More Posts

Follow Me:
TwitterFacebookLinkedIn

6 thoughts on “Fix PHP timezone warnings in OS X Snow Leopard

  1. Vito

    Thx so much. I can’t believe it, but no one has even raised a peep about this problem except, a few developers. I installed Snow leopard from my shiny new dvd that just arrived in the mail and when it finally boots into the new desktop, I’ve got no time and date function and nor can it be set in the system preferences.

    Thanks for being the only person to get the syntax correct.

    Vito

    Reply
  2. Vito

    Hello again,

    Now that the timezone issue is resolved, is there a way to fix DST in Snow Leopard via php as well. My terminal window shows the correct time, however my date and time in system preferences is broken; it is not updated online by cupertino and it refuses to allow me to set a date beyond say march something of 09 and sometimes of 07. The clock refuses to move from am to pm and instead places a minus sign in front of the hr numbers or sometimes not it does not save usually and if it does it is temporary as does the display in the bar before it disapears. Do you know of a way to approach this problem or even how to google it other than DST.
    Thx
    Vito

    Reply
  3. Peter Nicholls

    You know what, I’ve been hacking away at this stuff for a few years and the amount of issues and problems never fails to terrify me! Thank you to you guys, with out you I’d be LOST!

    HOWEVER: I still can’t get this one sorted!

    Thanks!
    Pete

    Reply
  4. Jose

    I fixed the problem using your method. May I ask what is the difference between php.ini and php.ini.default? Because in the second i had the line commented and deleting the semi-colon did nothing… Why is it that we have to create a php.ini with that simple command and not use the pre-existing one in php.ini.default?

    Reply
    1. Glen Post author

      php.ini.default is included by Apple in a Mac OS X install as a starting point for your own custom php.ini configuration. Rather than creating a php.ini file from scratch, you could copy php.ini.default to get a decent set of defaults.

      php.ini.default is not used by PHP at all which is why when you uncommented a line, nothing happened.

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.