Join the community today
Register Now

Wrong timezone in php error logs

Discussion in 'Nginx, PHP-FPM & MariaDB MySQL' started by BamaStangGuy, Jun 30, 2022.

  1. BamaStangGuy

    BamaStangGuy Active Member

    664
    191
    43
    May 25, 2014
    Ratings:
    +270
    Local Time:
    9:10 AM
    Has anyone been able to get the timezone changed for PHP error logs?

    No matter what I do, the error logs are the only thing that output UTC time.


    Everything else has correct timezone.

    Correct:
    Code:
    php -r "echo date('l jS \of F Y h:i:s A');"
    Thursday 30th of June 2022 07:54:28 AM
    Code:
    timedatectl
          Local time: Thu 2022-06-30 07:55:11 CDT
      Universal time: Thu 2022-06-30 12:55:11 UTC
            RTC time: Thu 2022-06-30 12:55:11
           Time zone: America/Chicago (CDT, -0500)
         NTP enabled: yes
    NTP synchronized: yes
     RTC in local TZ: no
          DST active: yes
     Last DST change: DST began at
                      Sun 2022-03-13 01:59:59 CST
                      Sun 2022-03-13 03:00:00 CDT
     Next DST change: DST ends (the clock jumps one hour backwards) at
                      Sun 2022-11-06 01:59:59 CDT
                      Sun 2022-11-06 01:00:00 CST
    Incorrect:
    Code:
    tail www-php.error.log
    [30-Jun-2022 11:02:19 UTC] This is the post causing the issue for profiles - 111886
    [30-Jun-2022 11:02:19 UTC] PHP Warning:  Attempt to read property "ID" on null in /home/nginx/domains/bamapolitics.com/public/wp-content/plugins/plugin-name/shortcodes/profiles.php on line 112
     
  2. eva2000

    eva2000 Administrator Staff Member

    49,301
    11,296
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +17,576
    Local Time:
    12:10 AM
    Nginx 1.21.x
    MariaDB 10.x
    PHP sets up it's own timezone config outside of system via date.timezone configuration paramter.
    Code (Text):
    php -i | grep 'timezone =>'
    Default timezone => UTC
    date.timezone => UTC => UTC
    


    For custom php settings read centminmod.com/phpfpm.html#customphpini. You might want to create /etc/centminmod/php.d/b_customphp.ini to override centmin mod defaults at /etc/centminmod/php.d/a_customphp.ini and restart PHP-FPM. Such changes will persist when doing centmin mod upgrades.

    Also outlined in Getting Started Guide Step 17

    example

    Code (Text):
    # check date.timezone
    php -r "print(date_default_timezone_get());"
    UTC
    
    # create custom override config /etc/centminmod/php.d/c_customphp.ini
    touch /etc/centminmod/php.d/c_customphp.ini
    # set date.timezone
    echo "date.timezone=America/Chicago" >> /etc/centminmod/php.d/c_customphp.ini
    # restart php-fpm service
    fpmrestart
    # recheck date.timezone
    php -r "print(date_default_timezone_get());"
    America/Chicago
    
     
  3. eva2000

    eva2000 Administrator Staff Member

    49,301
    11,296
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +17,576
    Local Time:
    12:10 AM
    Nginx 1.21.x
    MariaDB 10.x
    Oh you're referring to system log date timestamp being UTC ?

    That seems to be hardcoded to UTC PHP :: Bug #45191 :: error_log ignores date.timezone php.ini val when setting logging timestamps

    If it's just visual comparison issue when you inspect logs, you can use Centmin Mod's command shortcut = mytimes which lists common timezones so you can easily reference any date/timezones

    Code (Text):
    mytimes
    Thu Jun 30 13:43:51 UTC 2022    [UTC]
    Thu Jun 30 23:43:51 AEST 2022   [Australia/Brisbane]
    Thu Jun 30 06:43:51 PDT 2022    [America/Los_Angeles]
    Thu Jun 30 08:43:51 CDT 2022    [America/Chicago]
    Thu Jun 30 09:43:51 EDT 2022    [America/New_York]
    Thu Jun 30 09:43:51 EDT 2022    [America/Montreal]
    Thu Jun 30 14:43:51 BST 2022    [Europe/London]
    Thu Jun 30 15:43:51 CEST 2022   [Europe/Berlin]
    Thu Jun 30 20:43:51 +07 2022    [Asia/Bangkok]
    Thu Jun 30 20:43:51 +07 2022    [Asia/Ho_Chi_Minh]
    Thu Jun 30 20:43:51 WIB 2022    [Asia/Jakarta]
    Thu Jun 30 21:43:51 +08 2022    [Asia/Kuala_Lumpur]
    Thu Jun 30 21:43:51 +08 2022    [Asia/Singapore]
    
     
  4. BamaStangGuy

    BamaStangGuy Active Member

    664
    191
    43
    May 25, 2014
    Ratings:
    +270
    Local Time:
    9:10 AM
    This is the most annoying, doesn't really impact my life bug I have come across recently. Likely because of how old it is and how easy it should be to fix.

    PHP's error logs are the ONLY logs that do not respect my timezone.
     
  5. eva2000

    eva2000 Administrator Staff Member

    49,301
    11,296
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +17,576
    Local Time:
    12:10 AM
    Nginx 1.21.x
    MariaDB 10.x
    Well if you can find where in the PHP source code it hardcodes UTC in it, I can probably add to Centmin Mod's PHP compile routine an on the fly patch to change the hardcoded timezone :D
     
  6. BamaStangGuy

    BamaStangGuy Active Member

    664
    191
    43
    May 25, 2014
    Ratings:
    +270
    Local Time:
    9:10 AM
    I'll see what I can find, when I can find the time in my timezone to look lol