Set Timezone for MYSQL / PHP

After setting system time, I discovered that mysql and php services didn’t also update the timezone settings. Here’s how to make sure they also reflect the correct timezone.

First locate all the php.ini files in /etc

cd /etc/
find . | grep php.ini
./php/7.4/apache2/php.ini
./php/7.4/cli/php.ini

now edit these files and add the timezone info

nano ./php/7.4/apache2/php.ini

add this to the [Date] block:

[Date]
date.timezone = "America/New_York"

For mysqld portion, first copy timezone data into mysql tables:

mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root mysql

Now edit the mysqld.cnf file:

nano /etc/mysql/mysql.conf.d/mysqld.cnf

And add this to the [mysqld] block:

[mysqld]
default-time-zone='America/New_York'

Finally do a service restart:

systemctl restart mysql
systemctl restart apache2

That’s It, Enjoy!

By Matt

Just a normal run-of-the-mill linux hacker type.

1 comment

  1. I visited many websites, but yours is probably the most interesting I found, and your article "Set Timezone for MYSQL / PHP" is very interesting ! Keep going 🙂

Comments are closed.