设置 PHP 默认时区

发现自己搭建的 FreshRSS 推送流里的文章时间总是使用美国时区,所以想解决这一问题。

Issue #659 里看到开发者:

For the record, since PHP 5.1.0, it is mandatory to have a proper php.ini or similar configuration of the timezone http://php.net/date-default-timezone-set

看来需要修改 php.ini 这一配置。首先查看 PHP 信息来定位配置文件:

php --ini

输出:

phpinfo()
PHP Version => 7.4.13

System => [...]
[...]
Configuration File (php.ini) Path => /etc/php/7.4/cli
Loaded Configuration File => /etc/php/7.4/cli/php.ini
[...]

取消 /etc/php/7.4/cli/php.inidate.timezone的注释并修改其值1

[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = Asia/Shanghai

之后重启服务:

sudo service nginx reload
sudo /etc/init.d/php7.4-fpm restart

──发现一篇发布时间原本早上六点多的文章已经显示为下午两点多发布了。


  1. List of Supported Timezones: https://www.php.net/manual/en/timezones.php ↩︎


comments powered by Disqus