Prettyscripts

Linux and Php: Timezone Setting

Recently a server was upgraded to FC14 with PHP V538 and when running PHP based website, the following warning is displayed:

PHP Warning:  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 ‘Australia/Melbourne’ for ……

There are 2 ways to fix it.

In every startup PHP script

In the beginning of the script, add the following code:

date_default_timezone_set("your time zone");

Look for supported timezone here.

The downside with this method is, you must remember to add this code in every startup script.

In /etc/php.ini

If you have root access, this is the preferred option.

The timezone setting is commented out:

[Date]
; Defines the default timezone used by the date functions
;date.timezone = ""

Look for this setup, uncomment line 3 and enter your timezone string. Remember to restart or reload Apache.

You can forget about setting timezone in your code from now on.

Leave a Reply