The Community Forums

Interact with an entire community of cPanel & WHM users.
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

date_default_timezone_set()?

Discussion in 'General Discussion' started by BlazeHost, May 7, 2012.

  1. BlazeHost

    BlazeHost Member

    Joined:
    May 4, 2012
    Messages:
    13
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    I get a error when calling a date on my centos system with cpanel installed.
    It gives me this error
    Warning: phpinfo() [function.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 'Europe/Moscow' for 'MSD/4.0/DST' instead in
    How could I fix this?
     
  2. BlazeHost

    BlazeHost Member

    Joined:
    May 4, 2012
    Messages:
    13
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    Can anyone help with this please?
     
  3. cPanelTristan

    cPanelTristan Quality Assurance Analyst
    Staff Member

    Joined:
    Oct 2, 2010
    Messages:
    7,623
    Likes Received:
    21
    Trophy Points:
    38
    Location:
    somewhere over the rainbow
    cPanel Access Level:
    Root Administrator
    I've moved this thread to the appropriate location. The general lounge was never intended for asking actual questions about issues on the machine.

    You should be able to set this in the global php.ini file:

    Code:
    grep -q '^date.timezone' /usr/local/lib/php.ini || echo 'date.timezone="Europe/Moscow"' >> /usr/local/lib/php.ini
    The above command checked /usr/local/lib/php.ini file for a date.timezone line already existing. If it does, it will not insert the line. If it doesn't find the line, it will add it with Europe/Moscow as the timezone. You'd replace Europe/Moscow in the command with the applicable timezone to use based on these -> PHP: List of Supported Timezones - Manual

    If the php.ini file is not the global one for the account, then replace /usr/local/lib/php.ini in the command with the path to the user's php.ini file on the specific account.

    Thanks!
     
  4. BlazeHost

    BlazeHost Member

    Joined:
    May 4, 2012
    Messages:
    13
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    Its still not working after doing that.. Any idea?
     
  5. cPanelTristan

    cPanelTristan Quality Assurance Analyst
    Staff Member

    Joined:
    Oct 2, 2010
    Messages:
    7,623
    Likes Received:
    21
    Trophy Points:
    38
    Location:
    somewhere over the rainbow
    cPanel Access Level:
    Root Administrator
    Does the account have an individual php.ini file? If you are using suPHP, then that account might and "doing that" might simply mean that the global php.ini was revised but the account level one wasn't.
     
  6. gkgcpanel

    gkgcpanel Well-Known Member

    Joined:
    Jun 6, 2007
    Messages:
    217
    Likes Received:
    0
    Trophy Points:
    16
    cPanel Access Level:
    DataCenter Provider
    We are constantly getting customers complaints that they are getting the "it is not safe to rely on the system timezone settings" error. We do have the date.timezone=('America/Chicago') set in /usr/local/lib/php.ini and we do NOT allow users to have their own php.ini file. So they do use the default one.

    The fix is usually to open up whatever php file is calling the date function and add a line to the top of any php file that calls the date function. date_default_timezone_set('America/Chicago');

    However, this time, we have a user/customer that is using the WysiwigPro editor that comes with cPanel and he is getting this error while uploading a picture.

    phpinfo shows:

    Configuration File (php.ini) Path /usr/local/lib
    Loaded Configuration File /usr/local/lib/php.ini
    Scan this dir for additional .ini files /usr/local/lib/php.ini.d
    Additional .ini files parsed (none)

    date
    date/time support enabled
    "Olson" Timezone Database Version 2012.3
    Timezone Database external
    Default timezone America/Chicago

    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 no value no value

    Seems like the date.timezone is not being carried over from the Default (above).

    # grep '^date.timezone' /usr/local/lib/php.ini
    date.timezone=('America/Chicago')

    As you can see it is set. and we don't allow other php.ini files. So why is this still happening?
     
  7. gkgcpanel

    gkgcpanel Well-Known Member

    Joined:
    Jun 6, 2007
    Messages:
    217
    Likes Received:
    0
    Trophy Points:
    16
    cPanel Access Level:
    DataCenter Provider

    UPDATE:

    So here is a screen shot of the error as I saw it this morning.

    date_timezone_error_php.png

    Here's how I fixed this by modifying the following file:
    /usr/local/cpanel/base/3rdparty/wysiwygpro/core/libs/wproLangLoader.class.php

    At the top I added this:

    date_default_timezone_set('America/Chicago');

    The problem now went away...

    So back to my original question... Why is simply adding the date.timezone=('America/Chicago') to the /usr/local/lib/php.ini file not fixing the problem??? Why must we go into each and every PHP file that calls some date function and add the date_default_timezone_set('America/Chicago'); line???
     
  8. cPanelTristan

    cPanelTristan Quality Assurance Analyst
    Staff Member

    Joined:
    Oct 2, 2010
    Messages:
    7,623
    Likes Received:
    21
    Trophy Points:
    38
    Location:
    somewhere over the rainbow
    cPanel Access Level:
    Root Administrator
    The internal php.ini for cPanel is a different php.ini than the global one for websites. It is located at /usr/local/cpanel/3rdparty/etc/php.ini location. To make revisions to it, you'd need to edit /usr/local/cpanel/3rdparty/etc/php.ini.dist file and re-start cPanel or cpsrvd. After that, you'd want to add it to the exclude:

    Code:
    echo "/usr/local/cpanel/3rdparty/etc/php.ini.dist" >> /etc/cpanelsync.exclude
    I cannot say why it isn't working for websites themselves, though. I'd suggest opening up a ticket for why the global php.ini isn't working with the timezone set.
     
  9. gkgcpanel

    gkgcpanel Well-Known Member

    Joined:
    Jun 6, 2007
    Messages:
    217
    Likes Received:
    0
    Trophy Points:
    16
    cPanel Access Level:
    DataCenter Provider
    Tristan,

    Thanks for that information. Shouldn't the default cPanel php.ini already have a date/timezone set ???

    As to the original issue. I created a test.php file in one of my customers directories.

    This is all it as in it.
    Code:
    <?php
    echo date('l jS \of F Y h:i:s A');
    ?>
    
    When you call it from a browser, the correct date/time is displayed, but in the users error_log file, it shows this:

    [11-Jun-2012 14:35:42 UTC] PHP Warning: date() [<a href='function.date'>function.date</a>]: 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 'CDT/-5.0/DST' instead in /home/XXXXXXXX/public_html/test.php on line 3

    Then I went back and edited the test.php file:

    Code:
    <?php
    date_default_timezone_set('America/Chicago');
    echo date('l jS \of F Y h:i:s A');
    ?>
    
    Saved the file and called the test.php script again. The date/timezone still
    displays correctly and now, no more error message in the error_log file.
     
  10. cPanelTristan

    cPanelTristan Quality Assurance Analyst
    Staff Member

    Joined:
    Oct 2, 2010
    Messages:
    7,623
    Likes Received:
    21
    Trophy Points:
    38
    Location:
    somewhere over the rainbow
    cPanel Access Level:
    Root Administrator
    As stated, go ahead and submit a ticket. I cannot say why it isn't working. We have to access the system to do so. I only know how you edit the internal cPanel php.ini properly to distill changes and what should be in those files already and what should work. If those things do not, then that's ticket submission time. Thanks!
     

Share This Page