Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Fix Apache Log Times Differing from Server & PHP Time

· 6 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

When your Apache access and error logs show timestamps that don't match your server's clock or the time PHP reports, it usually comes down to one of three things: the server's timezone is set incorrectly, Apache is using a different timezone than the system, or PHP's timezone setting overrides the system default. This guide walks you through identifying the mismatch and aligning all three so your logs are consistent and trustworthy.

What You'll Need

  • Command-line access to your server (SSH or local terminal)
  • Root or sudo privileges to edit Apache and PHP configuration files
  • Basic familiarity with the date command and editing text files

Step-by-Step

  1. Check the current system time and timezone. Run date in your terminal. It shows the current date, time, and timezone (e.g., Mon Apr 14 09:30:00 UTC 2025). Note the timezone abbreviation—this is your server's baseline.
  2. Check what PHP thinks the timezone is. Create a temporary PHP file with <?php echo date_default_timezone_get(); ?> and access it via your web server, or run php -r "echo date_default_timezone_get();" from the CLI. If it differs from the system timezone, PHP is overriding it.
  3. Check Apache's log format. Look at your Apache config (usually /etc/apache2/apache2.conf or /etc/httpd/conf/httpd.conf) for the LogFormat directive. The default combined format includes %t, which is the time the request was received, formatted as [18/Sep/2025:14:30:00 +0000]. The +0000 is the offset from UTC. If this offset doesn't match your server's timezone, Apache is logging in a different zone.
  4. Set the system timezone correctly. On most Linux systems, use sudo timedatectl set-timezone Your/Zone (e.g., America/New_York). On older systems, edit /etc/timezone or run sudo dpkg-reconfigure tzdata. Verify with date again.
  5. Set PHP's timezone to match. Edit your php.ini file (find its location with php --ini). Look for date.timezone and set it to the same zone you used for the system (e.g., date.timezone = America/New_York). If it's commented out, uncomment it. If you use a framework like Laravel or WordPress, they may set a timezone in their config—check those too.
  6. Restart Apache and PHP-FPM (if used). Run sudo systemctl restart apache2 (or httpd) and sudo systemctl restart php-fpm if you have it. This ensures all processes pick up the new timezone settings.
  7. Verify the logs now match. Generate a new request to your server (e.g., reload a page) and check the latest log entry. The timestamp should now show the correct local time with the correct offset. Also check PHP still reports the same timezone with the test file from step 2.

Common Mistakes

  • Forgetting to restart Apache or PHP-FPM. Changes to php.ini or Apache config won't take effect until the service restarts. Always restart both if you changed both.
  • Setting only PHP's timezone, not the system's. Apache's %t uses the system time by default. If you only fix PHP, your PHP-generated timestamps (like in error logs) will match PHP, but Apache's access logs will still be off.
  • Using a timezone abbreviation instead of a location. Setting date.timezone = EST is unreliable because EST doesn't account for daylight saving. Always use a full location like America/New_York.
  • Editing the wrong php.ini. There are often multiple php.ini files (CLI vs. Apache/FPM). Use php --ini to see which one is loaded for the CLI, and check phpinfo() to see which one Apache uses—they might be different.

Tips

  • Use UTC internally if you can. Many servers run in UTC to avoid daylight saving confusion. If your users are in one timezone, you can convert for display in your application. This keeps logs consistent across servers.
  • Set the timezone in your application code as a fallback. In PHP, you can call date_default_timezone_set('America/New_York') at the top of your script, but it's better to set it in php.ini so all scripts inherit it.
  • Check your hosting panel. If you're on shared hosting, you may have a .htaccess option like SetEnv TZ America/New_York or a PHP selector in cPanel. These can override system settings.
  • Monitor your logs after a timezone change. Look for any entries that are out of order—if you change from UTC to local time, old entries will appear to be in the future or past relative to new ones. That's expected.

Troubleshooting

If the logs still don't match after following the steps:

  • Check if Apache is using a custom log format. Some virtual hosts define their own LogFormat with %{%Y-%m-%d %H:%M:%S %z}t which forces a specific format and timezone. Search your config files for LogFormat and see if a timezone is hardcoded.
  • Verify the system timezone is actually applied. Run timedatectl and look at the "Local time" line. If it shows UTC but you set a different zone, the system clock may be set to UTC and the timezone is just a display setting. That's fine—Apache will use the offset correctly.
  • Check if PHP-FPM is running with a different php.ini . If you're using PHP-FPM, it may have its own pool configuration that sets . Look in /etc/php/*/fpm/pool.d/ for such overrides.
  • Test with a simple PHP script that prints both time and timezone. Create a file with <?php echo date('Y-m-d H:i:s T') . ' ' . date_default_timezone_get(); ?> and access it via the web. Compare that to the system date command. If they differ, PHP is the culprit.
  • Look at the raw log entry. Apache's %t includes an offset like +0000. If your server is in UTC+5, the offset should be +0500. If it's still +0000, Apache is not using the system timezone—check if you have a SetEnv TZ directive or if Apache was compiled with a fixed timezone.

Frequently Asked Questions

Why does Apache log in UTC even though my server is set to local time?

Apache uses the system's timezone by default, but some distributions or control panels set the TZ environment variable for Apache to UTC. Check your Apache environment with env or look for a SetEnv TZ directive in your config.

Do I need to change both Apache and PHP timezones?

Yes, because they are separate processes. Apache logs its own timestamps, and PHP logs its own (like errors). If you only change one, the other will still be off. The goal is to make both match the system time.

What if my hosting provider doesn't allow SSH access?

You can often set the timezone via a PHP ini override in a .htaccess file (if PHP runs as an Apache module) or via a PHP selector in your hosting control panel. For Apache logs, you may not be able to change the system timezone, but you can adjust the log format to display a different offset using %{%Y-%m-%d %H:%M:%S %z}t.

Will changing the timezone affect existing log entries?

No, existing entries keep their original timestamps. Only new entries will use the new timezone. If you change from UTC to local time, new entries will appear to be ahead of old ones, which can be confusing but is normal.

How do I find the correct timezone name for my region?

Run timedatectl list-timezones on Linux, or use the IANA timezone database to find the right Area/Location format (e.g., Europe/London).

Is it better to use UTC or local time for logs?

UTC is recommended for servers because it's unambiguous and avoids daylight saving issues. If you need local time for readability, you can convert in your log analysis tools. But if you must use local time, ensure all components (system, Apache, PHP) agree.