5

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!

Juan Sosa
  • 5,262
  • 1
  • 35
  • 41
Dimitri Vorontzov
  • 7,834
  • 12
  • 48
  • 76

7 Answers7

2

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.

Juan Sosa
  • 5,262
  • 1
  • 35
  • 41
  • Thank you Juan, yes, there are two php.ini files, one of them for php 5.2 and the other one for php 5.3. MAMP is running php5.3, so I've checked the corresponding php.ini file, and it has the date.timezone set correctly. I also tried your suggestion of adding date_default_timezone_get() function to those two files the way you described. No luck, I get the same exact warning message after saving the modified files. More insight would be appreciated. – Dimitri Vorontzov Nov 28 '12 at 05:24
  • I've never used MAMP but it should work that way. Try using `phpinfo()` in order to check which php.ini is Apache using and wether the `date.timezone` is set or not. Make sure you have restarted Apache after editing your `php.ini`. – Juan Sosa Nov 28 '12 at 05:44
  • Well, Juan, the problem is that MAMP seems to ignore some of the php.ini settings and to override them. In fact, it says so in the php.ini file: [Date] ; Defines the default timezone used by the date functions ; Will be changed by MAMP to system timezone ; date.timezone = "America/New_York" - as you can see, the text indiactes that MAMP overrides php.ini, so my initial question was, how to prevent MAMP from doing that... – Dimitri Vorontzov Nov 28 '12 at 06:27
  • P.S.I restarted the Apache, as you suggested, and still get the same warning. More ideas, please? – Dimitri Vorontzov Nov 28 '12 at 06:34
  • P.P.S. I just checked phpinfo, and to my horror realized that it includes the same warning message: 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 on line 2! Help please? – Dimitri Vorontzov Nov 28 '12 at 06:36
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.

Dimitri Vorontzov
  • 7,834
  • 12
  • 48
  • 76
1
  • 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"

Pedro Luz
  • 2,694
  • 4
  • 44
  • 54
0

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'
Community
  • 1
  • 1
Gonzalo
  • 400
  • 1
  • 9
0

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

jazzurro
  • 23,179
  • 35
  • 66
  • 76
Gonzalo
  • 400
  • 1
  • 9
0

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

solracid
  • 413
  • 5
  • 21
0

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 
HBR
  • 901
  • 1
  • 8
  • 15