PHP 5.3 and “It is not safe to rely on the system’s timezone settings”

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 = ‘Australia/NSW’

 

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]#

Bad Behavior has blocked 744 access attempts in the last 7 days.