strtotime() Date.Timezone Warning in CakePHP


If you are receiving the Warning: strtotime() It is not safe to rely on the system's timezone settings warning. You can solve this in several ways.

These are in reverse order of preference.

Editing php.ini

This is my preferred method. Locate the php.ini file on your system. I’m on a Mac so I can use the following to pipe the output of php info to grep.

Alternatively, you can create a php file on your server and use the phpinfo() function to output the php info to your browser. Locate the section which reads Configuration File (php.ini) Path.

On my system this it’s located in /etc.

If the file hasn’t been created for whatever reason, you can copy the php.ini.default and rename it to php.ini

Then use an editor to locate the line which reads date.timezone =. If it’s commented then remove the preceding ‘;’ and add your timezone in quotes to the setting.

Then just restart Apache sudo apachectl restart

.htaccess file

You can alter the timezone setting on a per site basis by adding the following line to an .htaccess in the root of your site.

To allow Apache to override your timezone settings in php.ini using this method you must make sure that AllowOverride Options or AllowOverride All is set in httpd.conf for the root of your web directory.

Here’s a list of available timezones

Cake Config

The third option is to set the default timezone within your CakePHP config. In your editor open /app/config/core.php from your cake project.

Find the line which reads //date_default_timezone_set('UTC'); and simply uncomment it.

Leave a Reply

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