可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
Greetings to StackOverflow gurus!
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.
Additionally, the page displays the following:
Warning: phpinfo() [function.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 'America/New_York' for 'EST/-5.0/no DST' instead in /Applications/MAMP/bin/mamp/phpinfo.php
In thr php.ini file, however, the setting is as follows:
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.
How can I remedy the issue? What am I missing?
Would be grateful for help from a knowledgeable person.
回答1:
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):
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.
回答2:
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.
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.
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.
/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.
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 = "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.
回答3:
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"
If set to 5.4.4, you must access /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
回答4:
If this error shows up in the terminal CLI usage of PHP, it might be an issue with native vs MAMP PHP collision.
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.
To do that, edit a .profile
(or bash RC file) text file and add this line to it:
export PATH="/Applications/MAMP/bin/php5.5.3/bin:$PATH"
Adjust the above path to point to your desired MAMP PHP install. Then run:
. ~/.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.
As a final check, run which php
to verify which PHP install path is being used. Hope this helps!
回答5:
In Ubuntu 13.10 using php 5.5.3
open your terminal and do
cd /
sudo find -name php.ini
it shows two files php.ini for me it results:
./etc/php5/apache2/php.ini
./etc/php5/cli/php.ini
open both files using sudo, I use 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
sudo service apache2 restart
It works for me!!!
回答6:
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.