我在执行 phpinfo() 时得到了
Warning: phpinfo(): It is not safe to rely on the system's timezone settings. You are required to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/Helsinki' for 'EET/2.0/no DST' instead in /myadmin/i.php on line 8
这是 i.php :
<?php
//echo date_default_timezone_get();
date_default_timezone_set("Europe/Kiev");
//echo date("l");
phpinfo();
?>
如您所见,当我执行 date_default_timezone_set("Europe/Kiev") 时,我得到:
Notice: date_default_timezone_set(): Timezone ID 'Europe/Kiev' is invalid in /myadmin/i.php on line 4
我确定我使用的是来自 here 的有效时区字符串,我确实设置了:
date.timezone = Europe/Kiev
在 php.ini 文件中。
环境:CentOS 6、nginx/1.1.11、PHP 5.3.8 (fpm-fcgi)
我实在想不明白这是怎么回事。 谢谢。
最佳答案
多亏了评论,我才得以解决我的问题。我在控制台中所做的:
#yum install php-pear
#pecl install timezonedb
它需要 c 编译器:
configure: error: no acceptable C compiler found in $PATH
...所以我做到了:
#yum install gcc
此外, 如果您收到有关 make 命令的错误,只需运行
#yum install make
最后,再试一次:
#pecl install timezonedb
...最后显示:
You should add "extension=timezonedb.so" to php.ini
我在/etc/php.ini 中添加了“extension=timezonedb.so”,然后重新启动了 php-fpm:
#/etc/init.d/php-fpm restart
关于php - 尽管时区有效,但设置默认时区不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8762608/