skip to Main Content

I’m facing a small issue with time zones in my Laravel application and would appreciate your help. I have a scheduled job in Laravel that updates event statuses. The job logs show the following timestamps in the laravel.log file:


[2024-08-19 09:58:18] local.INFO: Success: Checked at 2024-08-19 09:58:18  
[2024-08-19 09:58:18] local.INFO: Number of events updated to 'En cours': 0  
[2024-08-19 09:58:18] local.INFO: Number of events updated to 'Terminé': 4  

However, the actual local time is 10:58, not 09:58. I’ve checked the following:

Server Time Zone:

The server time zone is set correctly.
Laravel Configuration:

In config/app.php, I have:
php
Copy code
‘timezone’ => ‘UTC’,
I need the log times to reflect my local time zone (e.g., Central European Time). What should I change in my Laravel configuration or code to ensure that the job logs show the correct local time?

I want the job logs to reflect the local time zone (e.g., Central Africa Time) instead of UTC. How can I configure Laravel or the server to ensure that the job logs display the correct local time?

2

Answers


  1. Which Laravel version are you using? If you are using Laravel 11 there should be a key called APP_TIMEZONE which defaults to UTC.

    If this is not the case, and you are using an older version of Laravel, you should check out this answer on another question which is related to your question.

    https://stackoverflow.com/a/43539446/16909735

    Also, a good reference from the other post is the timezone list reference from the PHP documentation
    https://www.php.net/manual/en/timezones.php

    Login or Signup to reply.
  2. To make your Laravel application log timestamps in your local time zone (e.g., Central Africa Time), you need to change the timezone configuration in your config/app.php file and ensure that your server is correctly configured.

    1. Update Laravel Timezone Configuration

    In the config/app.php file, set the timezone to your desired local time zone, such as Africa/Johannesburg for Central Africa Time (CAT):

    'timezone' => 'Africa/Johannesburg',
    

    2. Server Timezone Configuration

    Ensure that your server’s time zone is correctly set to the desired local time zone. You can check and set the server time zone with the following commands, depending on your server’s operating system:

    For Ubuntu/Debian:

    sudo dpkg-reconfigure tzdata
    

    For CentOS/RHEL:

    sudo timedatectl set-timezone Africa/Johannesburg
    

    3. Restart Your Application

    After making these changes, restart your Laravel application to apply the new configuration:

    php artisan config:cache
    

    check the time on log file.

    This configuration should fix the time zone issue in your Laravel application logs.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search