简体   繁体   English

Symfony-MAMP(Windows)-警告时区

[英]Symfony - MAMP(windows) - warning timezone

I installed MAMP for windows 我为Windows安装了MAMP

I have this error since several hours... 几个小时以来我有这个错误...

    [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 me 
 thods and you are still getting this warning, you most likely misspelled th 
 e timezone identifier. We selected the timezone 'UTC' for now, but please s 
 et date.timezone to select your timezone.

In the php.ini concerned (C:/MAMP/conf/php5.5.19/php.ini), I changed the line DATE like this: 在有关的php.ini (C:/MAMP/conf/php5.5.19/php.ini),我将DATE行更改为:

    [Date]
; Defines the default timezone used by the date functions
date.timezone = "Europe/Paris"

And in my phpinfo() , the path loaded is : 在我的phpinfo() ,加载的路径是:

Loaded Configuration File   C:\MAMP\conf\php5.5.19\php.ini

When I do in the consol the command php --ini I have this : 当我在php --ini命令php --ini中执行以下操作时:

C:\Users\Thomas>php --ini
Configuration File (php.ini) Path: C:\Windows
Loaded Configuration File: (none)
Scan for additional .ini files in: (none)
Additional .ini files parsed:      (none)

Why Configuration File (php.ini) Path: is "C:\\Windows" and not C:\\MAMP\\conf\\php5.5.19\\ . 为什么Configuration File (php.ini) Path:"C:\\Windows"而不是C:\\MAMP\\conf\\php5.5.19\\ Can I change this Path ? 我可以更改此路径吗?

I don't know what to do now... 我现在不知道该怎么办...

thanks ! 谢谢 !

The problem is that your xAMP server and cli access uses different php configuration. 问题是您的xAMP服务器和cli访问使用不同的php配置。

One is C:\\Windows\\php.ini for CLI Second is C:\\MAMP\\conf\\php5.5.19\\php.ini for web server 一个是用于CLI的C:\\ Windows \\ php.ini第二个是用于Web服务器的C:\\ MAMP \\ conf \\ php5.5.19 \\ php.ini

Make sure you have updated both files. 确保已更新两个文件。

Secondly do not forget to restart xAMP server, as apache do not reload libapache2-mod-php5 configs automatically. 其次,不要忘记重启xAMP服务器,因为apache不会自动重新加载libapache2-mod-php5配置。

I had the same error. 我有同样的错误。 I had no clue where it was coming from, but with some trial and error I figured out it had something to do with the special character in my htdocs folder: 我不知道它的来源,但是经过反复试验,我发现它与htdocs文件夹中的特殊字符有关:

htdocs/Exámple htdocs中/例如

By changing that character to a normal character (thus changing to htdocs/Example), I no longer got the error and the site would load normally. 通过将该字符更改为普通字符(因此更改为htdocs / Example),我不再遇到错误,该站点将正常加载。

When you set configuration in MAMP it only affects PHP which is loaded in Apache module handler mode (mapped as module inside Apache process). 在MAMP中设置配置时,它只会影响以Apache模块处理程序模式(映射为Apache进程内的模块)加载的PHP。 If you want to set PHP CLI you need to set this separately from web server configuration. 如果要设置PHP CLI,则需要与Web服务器配置分开设置。

  • Open command prompt from Windows (cmd.exe from Start button) 从Windows打开命令提示符(“开始”按钮中的cmd.exe)
  • enter ECHO %PATH% 输入ECHO%PATH%
  • this command will list your current PATH variable with all paths. 该命令将列出所有路径的当前PATH变量。 For example, something like this: 例如,如下所示:

    C:>echo %PATH% C:>回声%PATH%

    C:\\Program Files (x86)\\EasyPHP-DevServer-14.1VC9\\binaries\\php\\php_runningversion ;C:\\ProgramData\\Oracle\\Java\\javapath;C:\\Perl\\site\\bin;C:\\Perl\\bin ... C:\\ Program Files(x86)\\ EasyPHP-DevServer-14.1VC9 \\ binaries \\ php \\ php_runningversion; C:\\ ProgramData \\ Oracle \\ Java \\ javapath; C:\\ Perl \\ site \\ bin; C:\\ Perl \\ bin .. 。

  • now enter following command 现在输入以下命令

    SET PATH=%PATH%;c:\\mamp\\bin\\php\\php5.6.0\\; SET PATH =%PATH%; c:\\ mamp \\ bin \\ php \\ php5.6.0 \\;

This will going to add path to php5.6.0 version from MAMP folder. 这将为MAMP文件夹中的php5.6.0版本添加路径。

  • you can now test your PHP CLI by entering following command : 您现在可以通过输入以下命令来测试PHP CLI:

    php -v 的PHP -V

  • then try to initialize configuration from MAMP for version PHP5.6.0 file: 然后尝试从MAMP初始化版本PHP5.6.0文件的配置:

    C:>php -c "c:\\mamp\\conf\\php5.6.0\\php.ini" --ini C:> php -c“ c:\\ mamp \\ conf \\ php5.6.0 \\ php.ini” --ini

    Configuration File (php.ini) Path: C:\\WINDOWS Loaded Configuration File: C:\\MAMP\\conf\\php5.6.0\\php.ini Scan for additional .ini files in: (none) Additional .ini files parsed: (none) 配置文件(php.ini)路径:C:\\ WINDOWS加载的配置文件:C:\\ MAMP \\ conf \\ php5.6.0 \\ php.ini扫描以下文件中的其他.ini文件:(无)解析的其他.ini文件:(无)

You can use command -c from PHP CLI to set path to configuration file; 您可以从PHP CLI使用命令-c来设置配置文件的路径。 and "c:\\mamp\\conf\\php5.6.0\\php.ini" is path to PHP ini file for version 5.6.0. 和“ c:\\ mamp \\ conf \\ php5.6.0 \\ php.ini”是版本5.6.0的PHP ini文件的路径。

If you do not want to always add path to configuration file with -c command, just copy php.ini file from C:\\MAMP\\conf\\php5.6.0\\ to C:\\MAMP\\bin\\php\\php5.6.0\\ 如果不想始终使用-c命令添加配置文件的路径,只需将php.ini文件从C:\\ MAMP \\ conf \\ php5.6.0 \\复制到C:\\ MAMP \\ bin \\ php \\ php5.6.0 \\

Off course, this will going to set PHP CLI only in currently opened command prompt. 当然,这只会在当前打开的命令提示符下设置PHP CLI。 To add this path permanently, you need to modify System Environment variable, or to use MAMP PRO as it already have this feature on PHP options page. 要永久添加此路径,您需要修改“系统环境”变量,或使用MAMP PRO,因为它在PHP选项页上已经具有此功能。

TL:DR - Make sure to edit both the ..\\MAMPPRO\\conf\\php[version].ini and the ..\\MAMP\\bin\\php\\php[version]\\php.ini with your correct/approved php timezone. TL:DR-确保使用正确/批准的php时区编辑..\\MAMPPRO\\conf\\php[version].ini..\\MAMP\\bin\\php\\php[version]\\php.ini


So while I was going through my setup, I had the same issue. 因此,当我进行设置时,遇到了同样的问题。

I was taking a look at my phpinfo() and it was giving me a path to my "Loaded Configuration File" that was located in my ..\\MAMPPRO\\conf\\php[version].ini so I was editing that file with approved timezone from http://php.net/manual/en/timezones.php making sure to avoid any from http://php.net/manual/en/timezones.others.php . 我正在查看我的phpinfo(),它为我提供了位于..\\MAMPPRO\\conf\\php[version].ini “已加载的配置文件”的路径,因此我正在以批准的方式编辑该文件http://php.net/manual/zh-cn/timezones.php中的时区,请确保避免使用http://php.net/manual/en/timezones.others.php中的任何时区。

After a few restarts and no success I started to dig a little further into where MAMP Pro was pulling that ini. 重新启动几次后没有成功,我开始进一步研究MAMP Pro的启动方式。

I found the solution in ..\\MAMP\\bin\\php\\php[version]\\php.ini . 我在..\\MAMP\\bin\\php\\php[version]\\php.ini找到了解决方案。 If I edited this file IN ADDITION TO editing the MAMP Pro ini everything worked properly. 如果我编辑MAMP Pro ini之外还编辑了此文件,则一切正常。

Hopefully this can help you out! 希望这可以帮助您!

在web / app_dev.php和web / app.php的开头,您可以添加:

date_default_timezone_set('Europe/Paris');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM