MAMP / Symfony: MAMP overrides date.timezone setting from php.ini, Symfony fails

ⅰ亾dé卋堺 提交于 2019-12-04 07:12:40

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.

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.

  • copy

cp /etc/php.ini.default /etc/php.ini

  • change permisions

chmod -R 775 /etc/php.ini

  • edit

sudo vi /etc/php.ini

  • search for date.timezone and change it to (example):

date.timezone = "Europe/London"

Gonzalo

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'
Gonzalo

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

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 :)

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 
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!