DEV Community

Pradeep Kumar
Pradeep Kumar

Posted on

2 1

Fixed: WHM (CPanel) + Laravel Timezone Issue

While hosting Laravel on WHM control panel, you need to make sure to set correct timezone at 4 places:

1. MySql Timezone
MySql time zone is taken from server time which can be update from:

WHM Login > Server Configuration > Server Time
Enter fullscreen mode Exit fullscreen mode

After update the Timezone you need to restart the server.

2. PHP Timezone
This will come from php.ini file. To update php.ini file you need to visit:

WHM Login > MultiPHP Manager > Editor Mode > Choose the PHP Version
Enter fullscreen mode Exit fullscreen mode

Update following variable:

date.timezone = "UTC"
Enter fullscreen mode Exit fullscreen mode

Restart apache and php-fpm service.

3. Laravel Timezone
Update laravel timezone in config/app.php:

...
'timezone' => 'UTC',
...

Enter fullscreen mode Exit fullscreen mode

4. Serialize Datetime
In your Laravel models, use following code:

protected function serializeDate(\DateTimeInterface $date)
{
    return $date->format('Y-m-d H:i:s');
}
Enter fullscreen mode Exit fullscreen mode

You can also create a Base.php model with the above code and extend all your models to Base model.

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay