date(): It is not safe to rely on the system’s timezone settings

label_outlinechat_bubble_outline Comment

Have you ever opened up your server log and seen an error like this: date(): It is not safe to rely on the system’s timezone settings? Or maybe the script that you’re attempting to execute won’t work because of this error. In this quick guide we’ll show you how to make the necessary changes to the php.ini file in order to resolve these errors.

First we need to find out what time zone your in. The complete list of supported php time zones can be located by clicking here.

For those of us in the United States, here’s a quick reference guide:

Eastern ........... America/New_York
Central ........... America/Chicago
Mountain .......... America/Denver
Mountain no DST ... America/Phoenix
Pacific ........... America/Los_Angeles
Alaska ............ America/Anchorage
Hawaii ............ America/Adak
Hawaii no DST ..... Pacific/Honolulu

Once you know what time zone you’re in you’ll need to locate your php.ini file. Do so by opening shell to your server and executing the following command:

find / -name php.ini

You should find that it’s located similar to /etc/php.ini (for the entire server) or /var/www/vhosts/system/domain.tld/etc/php.ini (Single Domain – Plesk).

Choose the appropriate php.ini file depending on whether or not you want the change applied globally to the entire server or just the domain.

Once you know where you want to place it execute the following command and replace the php.ini with the one of your choice.

nano /etc/php.ini

Now push ctrl-w to search in nano. Search for the word “timezone”. It should bring you to a location similar the the below:

; Defines the default timezone used by the date functions
; http://www.php.net/manual/en/datetime.configuration.php#ini.date.timezone
; date.timezone = 

We need to remove the trailing semi-colon from the date.timezone field and place the appropriate time zone after the equals sign. The revised version should look like:

; Defines the default timezone used by the date functions
; http://www.php.net/manual/en/datetime.configuration.php#ini.date.timezone
date.timezone = America/Chicago

If you decided to apply this just to the domain you might not be able to find the timezone setting in the domain php.ini. In order to add this variable you can simply scroll to the bottom of the file and add:

date.timezone = America/Chicago

You can also log into your Plesk control panel and add the above directive to the php.ini settings under the additional directives.

From all of us at WireFlare we ask that you help others find the answers they are looking for. Please leave a comment or share this post!

About

Blog Bio Picture For Todd

I'm the President of WireFlare. I have a passion for creativity, online business and internet security. I strive to create a community that empowers people to be themselves. I'm an adventurist, fun loving and caring. Find me hiking in places most people don't dare to go!

Get a free consultation today!