Learn about Centmin Mod LEMP Stack today
Become a Member

PHP-FPM TimeZone Setup

Discussion in 'Nginx, PHP-FPM & MariaDB MySQL' started by BoostN, Jan 7, 2015.

  1. BoostN

    BoostN Active Member

    134
    27
    28
    Aug 19, 2014
    Ratings:
    +42
    Local Time:
    4:03 PM
    1.13.6
    10.0.34
    So after reading it seems php has it's own timezone configuration and does not pull from the server (CentOS in my case). This is probably well known knowledge to most but I'm still pretty new to the configuration side of things on my server.


    So I see I have UTC in my phpinfo file. If I change this, will it require a php-restart? My cron jobs aren't running correctly on XenForo because of the time XenForo is picking up from PHP (I'm assuming).
     
  2. eva2000

    eva2000 Administrator Staff Member

    53,865
    12,160
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,712
    Local Time:
    8:03 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
  3. rc112

    rc112 Member

    126
    14
    18
    Sep 22, 2017
    Ratings:
    +15
    Local Time:
    6:03 AM
    Why there should be different timeozone for nginx, php and even mysql. I read this on DO.
    "Both php and mysql should have defaulted to system time, but if they aren't respecting that for some reason you can change them."
    But @eva2000 mentioned that he won't do so while having multiple server running on different timezone. Which is correct? Thanks all.
     
  4. eva2000

    eva2000 Administrator Staff Member

    53,865
    12,160
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,712
    Local Time:
    8:03 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    If system time = UTC, then php and mysql will use system time = UTC then all are ok. That is the default usually for Centmin Mod. No need to change timezones. I guess you're confusion is what it means by system time. System time by default = UTC.

    My comment is if related to where all servers should use UTC default. So if I have 4 servers in London, Sydney, New York and Singapore all should use UTC system time. That way if the servers are in a cluster or have issues, I can pin point issues easily according to one UTC timezone from all server's logs. But if each server had it's own local time. I'd have to look up each servers logs and convert each of their local times to UTC time and then figure out what happened where.

    Centmin Mod 123.09beta01 includes mytimes command which lists system default UTC timezone and common timezones for reference so you can still have system and logs in UTC and still get a quick conversion to a local time for figuring stuff out.
    Code (Text):
    mytimes
    Wed Mar  7 03:20:45 UTC 2018    [UTC]
    Wed Mar  7 13:20:45 AEST 2018   [Australia/Brisbane]
    Tue Mar  6 19:20:45 PST 2018    [America/Los_Angeles]
    Tue Mar  6 21:20:45 CST 2018    [America/Chicago]
    Tue Mar  6 22:20:45 EST 2018    [America/New_York]
    Tue Mar  6 22:20:45 EST 2018    [America/Montreal]
    Wed Mar  7 03:20:45 GMT 2018    [Europe/London]
    Wed Mar  7 04:20:45 CET 2018    [Europe/Berlin]
    Wed Mar  7 10:20:45 +07 2018    [Asia/Bangkok]
    Wed Mar  7 10:20:45 +07 2018    [Asia/Ho_Chi_Minh]
    Wed Mar  7 10:20:45 WIB 2018    [Asia/Jakarta]
    Wed Mar  7 11:20:45 +08 2018    [Asia/Kuala_Lumpur]
    Wed Mar  7 11:20:45 +08 2018    [Asia/Singapore]
    

    So using mytimes output, say you're in Singapore and get a server alert at 11 am for some issue. You log into server, run mytimes command above and see that Asia/Singapore time is currently 11:20 am. So the alert happened ~20 minutes. Look at first line UTC system time now is 3:20 am, so ~20 minutes ago was 3:00 am UTC time. I have the time I need to investigate in my server logs = 3:00 am UTC.

    You also want uniform server times like UTC if you have web server clusters or mysql database replication/clustering across servers located in different timezones to keep the internal system clock in sync with each other.
     
  5. rc112

    rc112 Member

    126
    14
    18
    Sep 22, 2017
    Ratings:
    +15
    Local Time:
    6:03 AM
    Hi @eva2000 Thanks for such detail. So if those servers are not in cluster or any related, it is okay to use any timezone for my suit, right? The benefit or the reason I want to use local time is it helps me to know when the alert happen in my local time so I can have a better sense if it is related to traffic peak or something. Thank you so much. I will keep learning and trying. :D
     
  6. eva2000

    eva2000 Administrator Staff Member

    53,865
    12,160
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,712
    Local Time:
    8:03 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    yeah single servers should be fine with local time but as i said mytimes command is there for that specifically too :)