php 警告:date_default_timezone_get() 安装 Symfony
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24251793/
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
Warning: date_default_timezone_get() installing Symfony
提问by dabecks
I'm trying to install Symfony on XAMPP and I keep getting numerous errors.
我正在尝试在 XAMPP 上安装 Symfony,但我不断收到许多错误。
[Symfony\Component\Debug\Exception\ContextErrorException]
Warning: date_default_timezone_get(): 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
/Applications/XAMPP/xamppfiles/htdocs/vendor/monolog/monolog/src/Monolog/Logger.php line 233
and then
进而
Script Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache handling the post-
install-cmd event terminated with an exception
and finally
最后
[RuntimeException]
An error occurred when executing the "'cache:clear --no-warmup'" command.
I've tried changing the date.timezone in my php.ini file and using the date_default_timezone_set() function in the command line before trying to install it and nothing seems to work.
我尝试在我的 php.ini 文件中更改 date.timezone 并在尝试安装之前在命令行中使用 date_default_timezone_set() 函数,但似乎没有任何效果。
I've been staring at it for a while so any help is appreciated
我一直盯着它一段时间,所以任何帮助表示赞赏
回答by qooplmao
If you can't set it correctly in your php.ini
for some reason then you can set it as the first thing in your AppKernel, like so..
如果php.ini
由于某种原因无法在您的应用程序中正确设置它,那么您可以将其设置为 AppKernel 中的第一件事,就像这样..
class AppKernel extends Kernel
{
public function __construct($environment, $debug)
{
date_default_timezone_set('Europe/London');
parent::__construct($environment, $debug);
}
public function registerBundles()
{
$bundles = array(
....
);
}
....
}
回答by Peter
Found a similar way to fix this issue while other didn't.
找到了解决此问题的类似方法,而其他方法则没有。
First check where the CLI php.ini is located:
php -i | grep "php.ini"
In my case I ended up with : Configuration File (php.ini) Path => /etc
Then
cd ..
all the way back andcd
into/etc
, dols
in my case php.ini didn't show up, only aphp.ini.default
Now, copy the php.ini.default file named as php.ini:
sudo cp php.ini.default php.ini
In order to edit, change the permissions of the file:
sudo chmod ug+w php.ini
sudo chgrp staff php.ini
Open directory and edit the php.ini file:
open .
Tip: If you are not able to edit the php.ini due to some permissions issue then copy 'php.ini.default' and paste it on your desktop and rename it to 'php.ini' then open it and edit it following step 7. Then move (copy+paste) it in /etc folder. Issue will be resolved.
Search for [Date] and make sure the following line is in the correct format:
date.timezone = "Europe/Amsterdam"
首先检查 CLI php.ini 所在的位置:
php -i | grep "php.ini"
就我而言,我最终得到了:配置文件 (php.ini) 路径 => /etc
然后
cd ..
所有的回道和cd
进/etc
,做ls
我的情况的php.ini没有露面,只有一个php.ini.default
现在,复制名为 php.ini 的 php.ini.default 文件:
sudo cp php.ini.default php.ini
为了编辑,更改文件的权限:
sudo chmod ug+w php.ini
sudo chgrp staff php.ini
打开目录并编辑 php.ini 文件:
open .
提示:如果由于某些权限问题您无法编辑 php.ini,请复制“php.ini.default”并将其粘贴到桌面上并将其重命名为“php.ini”,然后打开它并按照以下步骤进行编辑7. 然后将其移动(复制+粘贴)到 /etc 文件夹中。问题将得到解决。
搜索 [Date] 并确保以下行的格式正确:
date.timezone = "Europe/Amsterdam"
回答by Snowcrash
Edit your php.ini
(not necessarily at /etc/php.ini
- use php -i | grep ini
to find your version) and add your timezone.
编辑您的php.ini
(不一定在/etc/php.ini
- 用于php -i | grep ini
查找您的版本)并添加您的时区。
E.g. for America / New York it would be:
例如,对于美国/纽约,它将是:
date.timezone = "America/New_York"
回答by Jovan Perovic
It is very very common for WAMP
/XAMPP
and other stacks to have use of multiple php.ini
files - one for cli and one for web.
WAMP
/XAMPP
和其他堆栈使用多个php.ini
文件是非常常见的- 一个用于 cli,一个用于 web。
Since you're expiriencing the error from CLI try the following:
由于您正在体验来自 CLI 的错误,请尝试以下操作:
php -i | grep "php.ini"
this will output location of php.ini
used for cli. Edit the date.timezone
there.
这将输出php.ini
用于 cli 的位置。编辑date.timezone
那里。
As for the web mode, create a file foo.php
within your "web" directory of symfony containing only"
至于 web 模式,foo.php
在 symfony 的“web”目录中创建一个文件,只包含“
<?php phpinfo(); ?>
And, again, find the location of php.ini
used and edit the date.timezone
.
然后,再次找到php.ini
used的位置并编辑date.timezone
.
回答by StormLover
It's been mentioned but this is as simple as:
已经提到过,但这很简单:
sudo cp /etc/php.ini.default /etc/php.ini
须藤cp /etc/php.ini.default /etc/php.ini
You can't set the timezone if it can't find the php.ini file!!!!
如果找不到 php.ini 文件,则无法设置时区!!!!