[英]Warning: date_default_timezone_get() installing Symfony
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 我已经盯着它看了一段时间,所以对您的帮助表示赞赏
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(
....
);
}
....
}
Found a similar way to fix this issue while other didn't. 找到了类似的方法来解决此问题,而其他人则没有。
First check where the CLI php.ini is located: 首先检查CLI php.ini的位置:
php -i | grep "php.ini"
In my case I ended up with : Configuration File (php.ini) Path => /etc 以我为例,我最终得到:配置文件(php.ini)路径=> / etc
Then cd ..
all the way back and cd
into /etc
, do ls
in my case php.ini didn't show up, only a php.ini.default
然后
cd ..
一直返回到cd
到/etc
,在我的情况下ls
没有出现php.ini,只有一个php.ini.default
Now, copy the php.ini.default file named as php.ini: 现在,复制名为php.ini的php.ini.default文件:
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: 打开目录并编辑php.ini文件:
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. 提示:如果由于某些权限问题而无法编辑php.ini,请复制'php.ini.default'并将其粘贴到桌面上,并将其重命名为'php.ini',然后打开并按照以下步骤进行编辑7.然后将其移动(复制+粘贴)到/ etc文件夹中。 Issue will be resolved.
问题将得到解决。
Search for [Date] and make sure the following line is in the correct format: 搜索[日期],并确保以下行的格式正确:
date.timezone = "Europe/Amsterdam"
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. 这将输出用于cli的
php.ini
位置。 Edit the date.timezone
there. 在
date.timezone
编辑date.timezone
。
As for the web mode, create a file foo.php
within your "web" directory of symfony containing only" 至于网络模式,
foo.php
在“仅包含”的symfony的“网络”目录中创建文件foo.php
<?php phpinfo(); ?>
And, again, find the location of php.ini
used and edit the date.timezone
. 并且,再次找到
php.ini
使用位置并编辑date.timezone
。
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
查找您的版本)并添加您的时区。
Eg for America / New York it would be: 例如,对于美国/纽约,它将是:
date.timezone = "America/New_York"
See http://php.net/manual/en/timezones.america.php 参见http://php.net/manual/en/timezones.america.php
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文件,则无法设置时区!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.