≡ Menu

Linux: phpinfo() system’s timezone error date.timezone

I‘m getting the following errors in my log file whenever I use phpinfo() function:

[10-Jan-2011 18:39:08] PHP Warning: phpinfo(): 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 ‘America/Chicago’ for ‘CST/-6.0/no DST’ instead in /home/servers/http/dev/testpc.php on line 2

How do I fix this problem under UNIX / Linux php running Apache or lighttpd web server?

This problem or warning can be easily fixed by editing the /etc/php.ini file. Open a command-line terminal (select Applications > Accessories > Terminal), and then type the following commands or login using ssh to the remote server. First find out your timezone from /etc/sysconfig/clock file, enter:
# cat /etc/sysconfig/clock
ZONE="America/Chicago"
UTC=true
ARC=false

Edit /etc/php.ini, enter:
# vi /etc/php.ini
Make the changes as follows, enter (find date.timezone and update it as follows):

date.timezone="America/Chicago"

Save and close the file. Restart the Apache server:
# service httpd restart
If you are using lighttpd type the following to restart it:
# service lighttpd restart
Note: If you don’t have access to the /etc/php.ini file, add the following line in your php file before any date related functions:

<?php
   ....
   ....
        date_default_timezone_set("America/Chicago");
        phpinfo();
  ...
 ..
?>
Share this tutorial on:

Your support makes a big difference:
I have a small favor to ask. More people are reading the nixCraft. Many of you block advertising which is your right, and advertising revenues are not sufficient to cover my operating costs. So you can see why I need to ask for your help. The nixCraft, takes a lot of my time and hard work to produce. If you use nixCraft, who likes it, helps me with donations:
Become a Supporter →    Make a contribution via Paypal/Bitcoin →   

Don't Miss Any Linux and Unix Tips

Get nixCraft in your inbox. It's free:



{ 4 comments… add one }
  • BeDa January 18, 2011, 12:48 pm

    php.ini

    date.timezone = “US/Central”

  • Sri Prasanth March 28, 2012, 10:28 pm

    worked like a charm!! thanks a lot :)

  • Ryan September 4, 2012, 4:20 am

    I tried this and it didnt work for me

    cat /etc/sysconfig/clock
    ZONE="America/Los_Angeles"
    UTC=true
    ARC=false
    

    I’ve tried everything that I’ve found even on here.

    Time Zone Warning
    Similar to the Deprecated Warning, you may see the following warning in your logs
    PHP Warning: strtotime(): 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/Berlin’ for ‘CET/1.0/no DST’ instead in
    /usr/share/cacti/include/global_constants.php on line 156
    In this case, simply follow the directions. Set your timezone in /etc/php.ini
    ; Defines the default timezone used by the date functions
    ; http://www.php.net/manual/en/datetime.configuration.php#ini.date.timezone
    date.timezone =America/Regina
    Of course, read http://www.php.net/manual/en/datetime.configuration.php#ini.date.timezone , and find your correct timezone.
    As always, restart apache after any change to /etc/php.ini

    I still get this error.

    Warning: strtotime() [function.strtotime]: 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 ‘America/Los_Angeles’ for ‘PDT/-7.0/DST’ instead in /var/www/html/include/global_constants.php on line 165

  • Rodolfo Souza July 2, 2013, 12:31 pm

    Congratulations on topic …
    Very simple and helped me with such precision .. My error_log files were growing too!

    thank you

Leave a Comment

You can use these HTML tags and attributes: <strong> <em> <pre> <code> <a href="" title="">


   Tagged with: , , , , , , , , ,