Pradeep Kumar
Posted on August 5, 2022
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
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
Update following variable:
date.timezone = "UTC"
Restart apache
and php-fpm
service.
3. Laravel Timezone
Update laravel timezone in config/app.php
:
...
'timezone' => 'UTC',
...
4. Serialize Datetime
In your Laravel models, use following code:
protected function serializeDate(\DateTimeInterface $date)
{
return $date->format('Y-m-d H:i:s');
}
You can also create a Base.php
model with the above code and extend all your models
to Base
model.
💖 💪 🙅 🚩
Pradeep Kumar
Posted on August 5, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.