PHP和MySQL - 为什么依赖系统时间设置是不安全的?

There are so many places where you can modify the time settings in a set up of Linux, Apache, PHP, and MySQL. I need to set everything to UTC in my server and I wondered why not just set the system time to UTC and all services just need to use the timezone "SYSTEM" as I did for MySQL.

However, a simple PHP warning made me doubt my decision. "It is not safe to reply on the system's timezone settings"

I have to questions, one may lead to another.

  1. Why is it not safe to rely on the system time settings, specifically CentOS, in PHP, Apache, or MySQL?
  2. What is the best way to unify the time settings from all services: Apache, PHP, and MySQL?
  1. You should not rely on system settings as they can be changed accidentally, as simple as that. Instead, specifying the desired timezone in php.ini makes sure somebody gave this a thought and selected the correct timezone that is going to be used (unless overridden by ini_set)

  2. The best way is to specify the timezone you want in corresponding ini and conf files.

Moreover, if you have website now on US server and in few years you migrate to UK server, you want to copy your conf files as well and this assures that same timezone is used at all times.