Php – Incorrect timezone in PHP error logs

PHPtimezone

The timestamps in my PHP error log are being displayed in UTC. I want them to display in my local timezone.

  • The date.timezone property in my php.ini file is set to the correct timezone.
  • The output of phpinfo() displays the correct timezone.
  • The output of phpinfo() states that the correct php.ini file is loaded.
  • The server's clock is set to the correct timezone.

All of the websites I've found with Google just say to check those three things.

I'm using Windows Server 2019 and IIS.

Here is an example of what one of the lines in the log file currently looks like:

[28-Dec-2018 14:22:39 UTC] PHP Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in C:\path\media.php on line 694

Update: If I run a PHP script from the command line, and that script generates an error, the log entry DOES have a timestamp in my local timezone.

Best Answer

As per my comment, it sounds like your webserver is using the default log file format (W3C Extended) which uses GMT by default. The MS support page I linked contains two solutions for this.

The temporary solution is to run the following command on your log files:

c:\windows\system32\convlog -ie LogFileName -t ncsa:+/-GMTOffset

where LogFileName is the name of the file to convert and GMTOffset is the number of hours to correct. (for example -0500 for EST). NOTE: This solution does not actually change the time stamps for the log entries. It enters the GMT offset into each entry, so that anyone reading through the log can see that the time stamp is not in local time.

The following is an example of a log entry produced by this utility:

192.168.1.1 - - [30/Jun/2000:20:16:40 -0500] "GET /default.asp HTTP/1.0" 200

The best solution, it would seem, is to change the log file format to IIS log file format. I found the following guide in which Step 4 tells you how to do this:

https://docs.microsoft.com/en-us/iis/manage/provisioning-and-managing-iis/configure-logging-in-iis

This applies to Windows Server 2012, and Windows 8, but may be similar for your version. Please note the change can be applied at separate levels: Site, Per Site (Server), Per Server (Server).