无法在php.ini文件中设置date.timezone

Edx*_*dxz 21 php timezone datetime

每当我在PHP中使用日期函数时,我都在使用php5.5并收到此错误:

 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 the timezone 'UTC' for now, but please set date.timezone to select your timezone. in /var/www/info.php on line 1
Run Code Online (Sandbox Code Playgroud)

加载的配置文件在这里:

/etc/php5/apache2/php.ini 
Run Code Online (Sandbox Code Playgroud)

所以我将date.timezone设置更改为:

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

; http://php.net/date.default-latitude
;date.default_latitude = 31.7667

; http://php.net/date.default-longitude
;date.default_longitude = 35.2333

; http://php.net/date.sunrise-zenith
;date.sunrise_zenith = 90.583333

; http://php.net/date.sunset-zenith
;date.sunset_zenith = 90.583333
Run Code Online (Sandbox Code Playgroud)

然后我重启服务器:

sudo /etc/init.d/apache2 restart
Run Code Online (Sandbox Code Playgroud)

但仍然收到此错误,我试图检查附加ini文件位置中的.ini文件,但没有一个覆盖date.timezone设置

我已经检查了php.ini文件权限,但仍然无法正常工作请指导我解决这个问题,谢谢..

Dam*_*ati 17

试试这个:

date.timezone = "Asia/Jakarta"
Run Code Online (Sandbox Code Playgroud)

编辑:

让我们找到正确的php.ini.在apache/nginx /你使用的任何web服务器deamon中解雇这个(因为命令行版本可能与它使用的版本不同).

<?php
phpinfo();
?>
Run Code Online (Sandbox Code Playgroud)

什么是输出中的.ini?还是一样?

EDIT2:

在php.ini编辑之后,只需重新启动webserver(apache或nginx)......


Edx*_*dxz 15

终于解决了我的问题,这是我的加载配置文件:

/etc/php5/apache2/php.ini 
Run Code Online (Sandbox Code Playgroud)

在这里修改了date.timezone但它没有用.

因此,我在phpinfo()中检查"扫描此目录以获取其他.ini文件"值,该值指向:

/etc/php5/apache2/conf.d 
Run Code Online (Sandbox Code Playgroud)

然后我从该文件夹中的所有文件中搜索date.timezone但没有找到.

这是我在phpinfo()中的附加.ini文件解析值:

/etc/php5/apache2/conf.d/05-opcache.ini, /etc/php5/apache2/conf.d/10-pdo.ini, /etc/php5/apache2/conf.d/20-json.ini, /etc/php5/apache2/conf.d/20-mysql.ini, /etc/php5/apache2/conf.d/20-mysqli.ini, /etc/php5/apache2/conf.d/20-pdo_mysql.ini, /etc/php5/apache2/conf.d/20-xdebug.ini, /etc/php5/apache2/conf.d/30-mcrypt.ini 
Run Code Online (Sandbox Code Playgroud)

我修改了/etc/php5/apache2/conf.d/20-xdebug.ini,并附加了这一行:

date.timezone = Asia/Jakarta
Run Code Online (Sandbox Code Playgroud)

非常奇怪,但这解决了我的问题!


tem*_*ple 6

您应该通过找到php.in来检查,如果有某个地方有另一个.

为了我.命令行界面应该有CLI:

/etc/php5/cli/php.ini
/etc/php5/fpm/php.ini
Run Code Online (Sandbox Code Playgroud)

改变了 /etc/php5/cli/php.ini

它现在对我有用.