"phpinfo(): It is not safe to rely on the system's timezone settings..."

22,155

Solution 1

You have 2 options:

  1. Call this function date_default_timezone_set() before using any date functions. E.g. date_default_timezone_set("America/New_York");.

  2. Edit the php.ini file usually located at /usr/local/php/php.ini and change the date.timezone entry. Here is the list of supported timezones.

Solution 2

I solved this problem by find which php.ini your server is using. First, you should make a page show phpinfo(), and you visit the page, you can see the normal infomation; Second, find "Loaded Configuration File" in the page, you should see what php.ini file your server is using. like:"/etc/php.ini"; Third, you edit the certain file in your server, like: date.timezone="Asia/Shanghai" then restart the server. Done. Good luck.

Share:
22,155
Mark Satterfield
Author by

Mark Satterfield

Updated on July 09, 2022

Comments

  • Mark Satterfield
    Mark Satterfield almost 2 years

    While running a php installation script for Blue.box (front end to FreeSwitch PBX), I get this error about a timezone failure.

    Then I start digging. I'm not sure what is going on at this point. But here is what I have:

    I created an info.php file in my public_html directory that contains a single line:

    And I get this error and output

    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/New_York' for 'EDT/-4.0/DST' instead in /home/0default/public_html/info.php on line 1

    date/time
    
         support    enabled
        "Olson" Timezone Database Version   0.system
        Timezone Database   internal
        Default timezone    America/New_York
    
        Directive   Local Value Master Value
        date.default_latitude   31.7667 31.7667
        date.default_longitude  35.2333 35.2333
        date.sunrise_zenith 90.583333   90.583333
        date.sunset_zenith  90.583333   90.583333
        date.timezone   America/New_York    America/New_York
    

    I created a file /etc/php.d/timezone.ini with the following:

    [root@mercury php.d]# cat timezone.ini
    ; default time zone
    date.timezone='America/New_York'
    [root@mercury php.d]#
    

    I'm able to change timezone to America/Los_Angeles (for example), and after apache reboot the "date.timezone" field changes correctly.

    But I still get the error.

    Any ideas?

    --- Additional note ---

    If I change the /etc/php.d/timezone.ini file:

    [root@mercury php.d]# cat timezone.ini
    ; default time zone
    date.timezone='America/Los_Angeles'
    

    I can cause a change to the info.php output:

    date

    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/New_York' for 'EDT/-4.0/DST' instead in /home/0default/public_html/info.php on line 1

    date/time support   enabled
    "Olson" Timezone Database Version   0.system
    Timezone Database   internal
    Default timezone    America/New_York
    
    Directive   Local Value Master Value
    date.default_latitude   31.7667 31.7667
    date.default_longitude  35.2333 35.2333
    date.sunrise_zenith 90.583333   90.583333
    date.sunset_zenith  90.583333   90.583333
    date.timezone   America/Los_Angeles America/Los_Angeles
    

    --- Additional note ---

    For those who are learning (as I am), several .ini files are loaded. In the info.php output:

    Configuration File (php.ini) Path   /etc
    Loaded Configuration File   /home/0default/etc/php5/php.ini
    Scan this dir for additional .ini files /etc/php.d
    Additional .ini files parsed    /etc/php.d/curl.ini, /etc/php.d/dom.ini, /etc/php.d/fileinfo.ini, /etc/php.d/gd.ini, /etc/php.d/imap.ini, /etc/php.d/json.ini, /etc/php.d/mbstring.ini, /etc/php.d/mysql.ini, /etc/php.d/mysqli.ini, /etc/php.d/odbc.ini, /etc/php.d/pdo.ini, /etc/php.d/pdo_mysql.ini, /etc/php.d/pdo_odbc.ini, /etc/php.d/pdo_pgsql.ini, /etc/php.d/pdo_sqlite.ini, /etc/php.d/pgsql.ini, /etc/php.d/phar.ini, /etc/php.d/snmp.ini, /etc/php.d/sqlite3.ini, /etc/php.d/timezone.ini, /etc/php.d/wddx.ini, /etc/php.d/xmlreader.ini, /etc/php.d/xmlrpc.ini, /etc/php.d/xmlwriter.ini, /etc/php.d/xsl.ini, /etc/php.d/zip.ini
    

    The first one loaded is /etc/php.ini, then the "loaded configuration file", then the "scan this dir" files.

    So for example, one should be able to create a number of php web sites in different default timezones. Set the master default in /etc/php.ini, then allow each of the web sites to have a different time zone as identified in the "loaded..." section. Then, if one is concerned about any overrides, the master can again override with the /etc/php.d files.

    I've tried changing the "date.timezone" in each of the three locations, and successfully change the date.timezone as displayed by the info.php... but it does not modify the "Default timezone" value, which is the value that is causing the error.

    Another note, the .php script that I am running is actually Blue.box, a front end to FreeSwitch. So... I am hesitant in changing that .php script.