Fix Apache Log Times Differing from Server & PHP Time
In this article
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
datecommand and editing text files
Step-by-Step
- Check the current system time and timezone. Run
datein 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. - 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 runphp -r "echo date_default_timezone_get();"from the CLI. If it differs from the system timezone, PHP is overriding it. - Check Apache's log format. Look at your Apache config (usually
/etc/apache2/apache2.confor/etc/httpd/conf/httpd.conf) for theLogFormatdirective. The defaultcombinedformat includes%t, which is the time the request was received, formatted as[18/Sep/2025:14:30:00 +0000]. The+0000is the offset from UTC. If this offset doesn't match your server's timezone, Apache is logging in a different zone. - 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/timezoneor runsudo dpkg-reconfigure tzdata. Verify withdateagain. - Set PHP's timezone to match. Edit your
php.inifile (find its location withphp --ini). Look fordate.timezoneand 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. - Restart Apache and PHP-FPM (if used). Run
sudo systemctl restart apache2(orhttpd) andsudo systemctl restart php-fpmif you have it. This ensures all processes pick up the new timezone settings. - 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.inior 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
%tuses 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 = ESTis unreliable because EST doesn't account for daylight saving. Always use a full location likeAmerica/New_York. - Editing the wrong
php.ini. There are often multiplephp.inifiles (CLI vs. Apache/FPM). Usephp --inito see which one is loaded for the CLI, and checkphpinfo()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 inphp.iniso all scripts inherit it. - Check your hosting panel. If you're on shared hosting, you may have a
.htaccessoption likeSetEnv TZ America/New_Yorkor 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
LogFormatwith%{%Y-%m-%d %H:%M:%S %z}twhich forces a specific format and timezone. Search your config files forLogFormatand see if a timezone is hardcoded. - Verify the system timezone is actually applied. Run
timedatectland 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 systemdatecommand. If they differ, PHP is the culprit. - Look at the raw log entry. Apache's
%tincludes 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 aSetEnv TZdirective 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.