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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20451719/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 03:12:35  来源:igfitidea点击:

Cannot Set date.timezone In php.ini file

phpdatetimetimezone

提问by Edxz

I'm using php5.5 and getting this error whenever I used the date function in PHP:

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

 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

the loaded configuration file is here:

加载的配置文件在这里:

/etc/php5/apache2/php.ini 

so I changed the date.timezone setting into this:

所以我将 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

Then I restart the server:

然后我重新启动服务器:

sudo /etc/init.d/apache2 restart

but still getting this error, I tried to check the .ini file in the Additional ini file location but none of it is overriding the date.timezone setting

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

I've checked the php.ini file permission, but still not working please guide me to solve this problem, thanks..

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

采纳答案by Edxz

finally solved my problem, this is my Loaded Configuration File:

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

/etc/php5/apache2/php.ini 

modified the date.timezone here but it's not working.

在这里修改了 date.timezone 但它不起作用。

So, I check the "Scan this dir for additional .ini files " values in phpinfo() which point to:

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

/etc/php5/apache2/conf.d 

then I search date.timezone from all files in that folder but found none.

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

this is my Additional .ini file parsed value in phpinfo():

这是我在 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 

I modified /etc/php5/apache2/conf.d/20-xdebug.ini, and appended this line:

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

date.timezone = Asia/Jakarta

very weird but this solved my problem !!!

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

回答by Damiano Barbati

Try this:

尝试这个:

date.timezone = "Asia/Jakarta"

Edit:

编辑:

Let's locate the correct php.ini. Fire this within apache / nginx / whatever web server deamon your using (because the command line version may be different by the one used by it).

让我们找到正确的 php.ini。在 apache / nginx / 任何您使用的 Web 服务器守护程序中触发它(因为命令行版本可能与它使用的版本不同)。

<?php
phpinfo();
?>

What's the .ini in the output? Still the same?

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

Edit2:

编辑2:

After the php.ini edit, just restart the webserver (apache or nginx) ...

在 php.ini 编辑之后,只需重新启动网络服务器(apache 或 nginx)...

回答by temple

You should check out by locate php.in, if there somewhere has another one.

您应该通过定位 php.in 来查看,如果某处有另一个。

for me. there should have CLI for command line interface:

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

/etc/php5/cli/php.ini
/etc/php5/fpm/php.ini

change the /etc/php5/cli/php.ini

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

It works for me now.

它现在对我有用。

回答by Andrew Howden

Another solution for me after compiling PHP from source was to check php.ini was actually loading a config file. From command line

从源代码编译 PHP 后,我的另一个解决方案是检查 php.ini 是否实际加载了配置文件。从命令行

php --ini

returns

返回

Configuration File (php.ini) Path: /usr/local/lib
Loaded Configuration File:         (none)
Scan for additional .ini files in: (none)
Additional .ini files parsed:      (none)

Find it.

找到它。

find -name "php.ini" #it was in /usr/local/php/php.ini
cp /usr/local/php/php.ini /usr/local/lib/php.ini

Restart php (in my case, /etc/init.d/php-fpm stop, /etc/init.d/php-fpm start) and it works fine. For some reason it got copied wrong.

重新启动 php(在我的情况下,/etc/init.d/php-fpm stop, /etc/init.d/php-fpm start)并且它工作正常。由于某种原因,它被复制错了。

  • Distro: Centos 7
  • Web Server: Nginx
  • Type: EC2 Instance
  • 发行版:Centos 7
  • 网络服务器:Nginx
  • 类型:EC2 实例

回答by Victor Smirnov

I've faced the same issue recently with PHP 5.6.4.

我最近在使用 PHP 5.6.4 时遇到了同样的问题。

  • PHP 5.6.4 behaves strange
  • PHP 5.6.11 behaves normally as expected
  • PHP 5.6.4 表现奇怪
  • PHP 5.6.11 正常运行

When I put the date.timezoneconfiguration option under [PHP] section in the configuration file it works fine for PHP 5.6.4. For example I've added the option at the very beginning of the php.inifile

当我将date.timezone配置选项放在配置文件的 [PHP] 部分下时,它适用于 PHP 5.6.4。例如,我在php.ini文件的最开头添加了选项

[PHP]
date.timezone = "Europe/Stockholm"

But when I put the configuration option how this is shown in the example under [Date]section it does not work as expected, it looks like the option is ignored

但是,当我将配置选项放在示例下的示例中时,[Date]它没有按预期工作,看起来该选项被忽略了

[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
; this does not work for me for PHP 5.6.4 but works fine for PHP 5.6.11
date.timezone = "Europe/Stockholm"

When I add option to the 20-xdebug.inilike it is suggestion in the accepted answer https://stackoverflow.com/a/20731466/2111430the option is accepted because this file has only [PHP]section. Out of curiosity I tried other included inifiles and it looks like I can use any one.

当我添加选项时,20-xdebug.ini它是接受的答案https://stackoverflow.com/a/20731466/2111430 中的建议,该选项被接受,因为该文件只有[PHP]部分。出于好奇,我尝试了其他包含的ini文件,看起来我可以使用任何一个。

One more time, the issue happened for me only with PHP 5.6.4. When I changed the option on the server with PHP 5.6.11 it behaved exactly like I expected.

还有一次,这个问题只发生在我的 PHP 5.6.4 上。当我使用 PHP 5.6.11 更改服务器上的选项时,它的行为与我预期的完全一样。

回答by Accountant ?

In my case I had 2 date.timezone=records in the php.ini file and the last one was overriding the first one. removing one of them solved my problem.

就我而言,我date.timezone=在 php.ini 文件中有 2条记录,最后一条记录覆盖了第一条记录。删除其中一个解决了我的问题。

Also don't forget you need to restart the web server process.

另外不要忘记您需要重新启动 Web 服务器进程。

回答by mukund

Check for the conflicting settings in you php.ini, I had same issue and in my case xdebug settings defined before date.timezone causing this thing: For more detail refer: PHP Xdebug issue - date.timezone & session.save_path undefined

检查 php.ini 中是否存在冲突设置,我遇到了同样的问题,在我的情况下是在 date.timezone 之前定义的 xdebug 设置导致了这件事:有关更多详细信息,请参阅:PHP Xdebug 问题 - date.timezone & session.save_path undefined

回答by user3922395

It worked for me when I noticed that the date.timezone entry in php.ini was commented out. After removing the semicolon the timezone was set correctly.

当我注意到 php.ini 中的 date.timezone 条目被注释掉时,它对我有用。删除分号后,时区设置正确。

回答by minhajul

some command line php application installer (like the symfony installer, or even when php scripts are run from cli), use the ini file inside the php-cli directory

一些命令行 php 应用程序安装程序(如 symfony 安装程序,甚至当 php 脚本从 cli 运行时),使用 php-cli 目录中的 ini 文件

/etc/php5/cli/php.ini

/etc/php5/cli/php.ini



this solved my similar issue in dependency checking process while installing Symfony.

这解决了我在安装 Symfony 时在依赖项检查过程中的类似问题。

回答by paralaks

If you set the date.timezone value in php.ini but it does not work (ie. local value and master value are different) then you might need to update something like this in your apache configuration file:

如果您在 php.ini 中设置了 date.timezone 值但它不起作用(即本地值和主值不同)那么您可能需要在您的 apache 配置文件中更新如下内容:

<IfModule mod_php5.c>
  php_value date.timezone "Europe/Paris"
</IfModule>