可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
I'm trying to configure Symfony2 framework in MAMP.
In php.ini
I have correctly set date.timezone
, however, it appears that MAMP somehow overrides the setting and uses system time instead.
As a result, Symphony's config.php
page sends this warning:
Warning: date_default_timezone_get()
[function.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 'America/New_York' for 'EST/-5.0/no DST' instead in
/Applications/MAMP/htdocs/Symfony/app/SymfonyRequirements.php on line
434
Symfony fails to show start page until this has been fixed. What would be the solution?
Thank you!
回答1:
Check if there are two php.ini
files in your system. You may be adding the date.timezone
line in one of them but MAMP is using the other.
If that doesn´t work for you try adding the following line at the beginning of your web/app.php
and web/app_dev.php
files, (as the error message suggests):
date_default_timezone_get('Europe/London');
Hope it helps.
回答2:
I am still working on figuring out why and how MAMP overrides the php.ini date.timezone settings, however, I have found the quick fix solution within Symfony php files, which solved the problem, at least for now.
I added the following bit of code:
date_default_timezone_set ('America/New_York');
-- at the top of Symfony's config.php and app_dev.php files, immediately after the opening php tag, at the very top of the script. This removed the warning message and got Symfony working on MAMP.
I foresee having to add the same code to some other php files inside Symfony as I keep hacking at it, which shouldn't be a problem. Or I may figure out how to override MAMP's overriding.
Still, this is a workable solution.
回答3:
cp /etc/php.ini.default /etc/php.ini
chmod -R 775 /etc/php.ini
sudo vi /etc/php.ini
- search for
date.timezone
and change it to (example):
date.timezone = "Europe/London"
回答4:
Are you in command line? cause command line may get a different php.ini than MAMP.
To see which is your php.ini from command line, you can do:
$ php -i | grep 'Configuration File'
(reference: How to find the php.ini file used by the command line?)
Try to set "date.timezone" in "/etc/php.ini", or wherever it says is your php.ini file.
You can also change your php.ini file:
$ php -help | grep "php.ini"
-c <path>|<file> Look for php.ini file in this directory
Like...
$ php -c /Applications/MAMP/conf/php5.5.14/php.ini ...
For example:
$ php -c /Applications/MAMP/conf/php5.5.14/php.ini -i | grep 'Configuration File'
回答5:
If your problem is how to make changes in php.ini file on MAMP PRO, try to edit the template.
File -> Edit Template
You can see in MAMP manual, page 24
More info is here
回答6:
In MAMP 3.0.1 the php.ini file in the corresponding php folder version you are using has the value date.timezone declared after a semicolon which turns it into a comment rather than a command. In the php.ini in C:\MAMP\conf\php5.5.12 (or your php version) delete the semicolon in line 703 and define your local time according to guidelines http://php.net/manual/en/timezones.php.
Hope this works for you :)
回答7:
Like Pedro Luz mentioned, you have to set the timezone in your mac's php.ini and not MAMP's.
Don't forget to restart your mac's apache:
sudo /usr/sbin/apachectl restart
This solution worked for me:
[OK]
Your system is ready to run Symfony2 projects