MAMP / PHP.INI:phpinfo() 中的“date.timezone”设置显示“无值”,即使该值是在 php.ini 中设置的
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13795068/
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
MAMP / PHP.INI: "date.timezone" setting in phpinfo() shows "no value" even though the value is set in php.ini
提问by Dimitri Vorontzov
Greetings to StackOverflow gurus!
向 StackOverflow 大师问好!
Here's the issue I'm struggling with.
这是我正在努力解决的问题。
I run phpinfo() in MAMP, and the resulting table shows "no value" in both columns of the date.timezone row.
我在 MAMP 中运行 phpinfo(),结果表在 date.timezone 行的两列中都显示“无值”。
Additionally, the page displays the following:
此外,该页面还显示以下内容:
Warning:phpinfo() [function.phpinfo]: It is not safe to rely on the system's timezone settings. You are requiredto 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 'America/New_York' for 'EST/-5.0/no DST' instead in /Applications/MAMP/bin/mamp/phpinfo.php
警告:phpinfo() [function.phpinfo]:依赖系统的时区设置是不安全的。您需要使用 date.timezone 设置或 date_default_timezone_set() 函数。如果您使用了这些方法中的任何一种并且仍然收到此警告,则很可能是您拼错了时区标识符。我们在/Applications/MAMP/bin/mamp/phpinfo.php 中为“EST/-5.0/no DST”选择了“America/New_York”
In thr php.ini file, however, the setting is as follows:
然而,在 thr php.ini 文件中,设置如下:
date.timezone = America/New_York
date.timezone = America/New_York
I foresee the recommendation to check that the path to php.ini is correct - I've already done that, and the path is indeed correct: /Applications/MAMP/conf/php5.3/php.ini - that IS the file that has the value set.
我预见到检查 php.ini 路径是否正确的建议 - 我已经这样做了,并且路径确实是正确的:/Applications/MAMP/conf/php5.3/php.ini - 那是那个文件设置了值。
How can I remedy the issue? What am I missing?
我该如何解决这个问题?我错过了什么?
Would be grateful for help from a knowledgeable person.
将不胜感激有知识的人的帮助。
采纳答案by wizzard
If the timezone is set correctly in the pertinent php.ini file and you are still getting this message, you can try setting your TZ environment variable. Edit your .profile to add the following line (sub in your own timezone string):
如果在相关的 php.ini 文件中正确设置了时区并且您仍然收到此消息,您可以尝试设置您的 TZ 环境变量。编辑您的 .profile 以添加以下行(子在您自己的时区字符串中):
export TZ="America/New_York"
Not sure why (a) MAMP overrides your php.ini setting, (b) PHP doesn't throw a notice/warning when using the TZ env variable even though it says it will, but this solution worked for me using MAMP 2.0.5 with PHP 5.3.6.
不知道为什么 (a) MAMP 会覆盖您的 php.ini 设置,(b) PHP 在使用 TZ env 变量时不会发出通知/警告,即使它说会,但这个解决方案对我使用 MAMP 2.0.5 有效使用 PHP 5.3.6。
回答by JoeMoe1984
I know I might be a little late in answering this but I see on a few sites that you are asking about setting the correct timezone in MAMP.
我知道我回答这个问题可能有点晚了,但我在一些网站上看到您询问在 MAMP 中设置正确的时区。
It should be noted that there are two locations for a php.ini file for the version of php you are using. MAMP could be loading it from a different path then the one you are editing.
应该注意的是,对于您使用的 php 版本,php.ini 文件有两个位置。MAMP 可能从与您正在编辑的路径不同的路径加载它。
For example, lets say we are using php 5.3. Here are two locations of a php.ini file that could confuse someone on which one to edit.
例如,假设我们使用的是 php 5.3。以下是 php.ini 文件的两个位置,可能会混淆要编辑的位置。
/Applications/MAMP/bin/php/php5.3/conf/php.ini
You seem to be editing it at this location below:
您似乎正在下面的这个位置编辑它:
/Applications/MAMP/conf/php5.3/php.ini
Editing the timezone in the second path did not work for me but editing the one in the first one did. It could be that you are editing the wrong file even though it looks the same. I have tested this on my version. Running <?php phpinfo(); ?>in a php file and checking the path of the php.ini file will always show the correct path.
在第二条路径中编辑时区对我不起作用,但在第一个路径中编辑时区对我有用。可能是您编辑了错误的文件,即使它看起来相同。我已经在我的版本上测试过了。<?php phpinfo(); ?>在 php 文件中运行并检查 php.ini 文件的路径将始终显示正确的路径。
Also just to point out, using double quotes around the value of date.timezone will work. For example in my php.ini file the following works.
还要指出的是,在 date.timezone 的值周围使用双引号将起作用。例如,在我的 php.ini 文件中,以下工作有效。
date.timezone = "America/Vancouver"
Also the default value was encapsulated in double quotes as well.
此外,默认值也封装在双引号中。
I was also using MAMP version 2.1.1 when testing this out.
我在测试时也使用了 MAMP 2.1.1 版。
回答by Bruno Alano
Note that there are different versions of PHP in the /Applications/MAMP/conf. You should check which version you are using into the MAMP -> Preferences -> Tab "PHP"
请注意,/Applications/MAMP/conf中有不同版本的 PHP 。您应该在 MAMP -> Preferences -> Tab "PHP" 中检查您使用的版本
If set to 5.4.4, you must access /Applications/MAMP/conf/php5.4.4/php.ini
如果设置为5.4.4,则必须访问/Applications/MAMP/conf/php5.4.4/php.ini
@edit
@编辑
Run in Terminal this:
在终端中运行:
sed -i '$ a\date.timezone = "America/New_York"' /Application/MAMP/conf/php{5.4.4,5.2.17,5.3.13,5.3.14,5.3.5,5.4.3}/php.ini
or
或者
sed -i 's/date.timezone = "Europe/Berlin"/date.timezone = "America/New_York"/g' /Application/MAMP/conf/php{5.4.4,5.2.17,5.3.13,5.3.14,5.3.5,5.4.3}/php.ini
回答by Nick Matantsev
If this error shows up in the terminal CLI usage of PHP, it might be an issue with native vs MAMP PHP collision.
如果此错误出现在 PHP 的终端 CLI 用法中,则可能是本机与 MAMP PHP 冲突的问题。
MacOS X comes with its own PHP version pre-installed and that's what runs in the shell when you type php. MAMP's PHP config is separate from pre-installed PHP config: changing MAMP PHP timezone setting does not affect what you see in CLI - hence the timezone error persists. A quick way to check is to run which php- if you do not see a path starting with /Applications/MAMP/...you need to adjust your environment.
MacOS X 预装了自己的 PHP 版本,当您输入php. MAMP 的 PHP 配置与预安装的 PHP 配置分开:更改 MAMP PHP 时区设置不会影响您在 CLI 中看到的内容 - 因此时区错误仍然存在。检查的快速方法是运行which php- 如果您没有看到以 开头的路径,则/Applications/MAMP/...需要调整您的环境。
To do that, edit a .profile(or bash RC file) text file and add this line to it:
为此,请编辑.profile(或 bash RC 文件)文本文件并向其中添加以下行:
export PATH="/Applications/MAMP/bin/php5.5.3/bin:$PATH"
Adjust the above path to point to your desired MAMP PHP install. Then run:
调整上述路径以指向您所需的 MAMP PHP 安装。然后运行:
. ~/.profile
hash -r
That will apply the PATH change immediately (otherwise you'd need to open a new terminal window to apply changes). The second command is just a bash CLI cache clearing command.
这将立即应用 PATH 更改(否则您需要打开一个新的终端窗口来应用更改)。第二个命令只是一个 bash CLI 缓存清除命令。
As a final check, run which phpto verify which PHP install path is being used. Hope this helps!
作为最后的检查,运行which php以验证正在使用哪个 PHP 安装路径。希望这可以帮助!
回答by Simonts Cedeno
In Ubuntu 13.10 using php 5.5.3 open your terminal and do
在 Ubuntu 13.10 中使用 php 5.5.3 打开终端并执行
cd /
sudo find -name php.ini
it shows two files php.ini for me it results:
它为我显示了两个文件 php.ini 结果:
./etc/php5/apache2/php.ini
./etc/php5/cli/php.ini
open both files using sudo, I use nano
使用 sudo 打开两个文件,我使用 nano
sudo nano /etc/php5/apache2/php.ini
find and edit this line:
找到并编辑这一行:
;date.timezone =
and change to:
并更改为:
date.timezone = America/Caracas
Save and close this file and edit another
保存并关闭此文件并编辑另一个
sudo nano /etc/php5/cli/php.ini
find and edit this line:
找到并编辑这一行:
;date.timezone =
and change to:
并更改为:
date.timezone = America/Caracas
Save and close and restart apache with
保存并关闭并重新启动apache
sudo service apache2 restart
It works for me!!!
这个对我有用!!!
回答by Jon
grep -lr "Berlin" * | xargs sed -i .backup -e 's#Europe/Berlin#America/New_York#g'
grep -lr "Berlin" * | xargs sed -i .backup -e 's#Europe/Berlin#America/New_York#g'
The command above needed some finesse in my case. This will create backup files as well.
就我而言,上面的命令需要一些技巧。这也将创建备份文件。

