26

Can anyone tell me why am I getting this error when running app/console in a brand new formatted macbook with the latest MAMP installed ?

Warning: 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 'Europe/Helsinki' for 'EEST/3.0/DST' instead in /../Logger.php line 112

I have checked the path of php.ini and marked out the date.timezone = "Europe/Athens"

Also restarted MAMP/apache several times.

BryanH
  • 5,826
  • 3
  • 34
  • 47
Radolino
  • 1,834
  • 4
  • 26
  • 48
  • I posted an answer for similar error on DotProject [here](https://stackoverflow.com/questions/23162437/warning-date-default-timezone-get/53508519#53508519) – Sandi Laufenberg-Deku Nov 27 '18 at 21:52

10 Answers10

22

At AppKernel.php write:

public function init() {
    date_default_timezone_set( 'Europe/Lisbon' );
    parent::init();
}

Since init() is deprecated (and will be remove in Symfony2 3.0) it is recommended to move the code in the constructor as in the following exemple:

public function __construct($environment, $debug) {
    parent::__construct($environment, $debug);
    // get rid of Warning: date_default_timezone_get(): It is not safe to rely on the system's timezone
    date_default_timezone_set( 'Europe/Paris' );
}
BaCaRoZzo
  • 7,502
  • 6
  • 51
  • 82
21

Default php.ini in OS X is located at:

/private/etc/php.ini

Anyway, you'll can either tell CLI php to load MAMP settings, or use an alias of MAMP command itself.

Community
  • 1
  • 1
moonwave99
  • 21,957
  • 3
  • 43
  • 64
  • 3
    MAC OS X and MAMP together is a total crap. It took me hours in a brand new installation of MAC OS X Mountain Lion to make half of the things work and I am not totally inexperienced. MAC OS X has two apache services and some php.ini's (and other files needed) here and there. Still cannot make all things work 100% and I am not sure I know how to remove the MAC OS apache and replace it with MAMP's one. – Radolino Sep 24 '12 at 05:34
  • If you start apache via MAMP widget, it is the one that server pages at localhost. If you make an alias to MAMP php command, it is the one used by CLI - as simple :)) I used MAMP for years, then I went with native Apache+PHP because I didn't need an external tool anymore. – moonwave99 Sep 24 '12 at 11:37
  • @RobertoDelgazzo Crap? Not at all. Don't remove the built-in anythings (apache/php), just disable them and install the latest versions in `/opt/local`. – BryanH Jan 23 '13 at 23:01
  • 1
    It is crap! Try using Python with MAMP, they put the MySQL in some odd place. It's easier to just use the built in PHP, Apache2 and add MySQL. – Peter Wooster Apr 25 '13 at 01:00
  • In order to identify the `php.ini` used by apache, execute the following command: `php -i | grep php.ini`. – Joël Salamin Sep 24 '14 at 20:17
8

You don't edit the good php.ini file

You can get a full phpinfo() using :

php -i 

And, in there, there is the php.ini file used :

$ php -i | grep 'Configuration File'
Configuration File (php.ini) Path => /etc
Loaded Configuration File => /etc/php.ini
acubens
  • 472
  • 1
  • 8
  • 17
  • 4
    I am getting Loaded Configuration File => (none) – Radolino Sep 22 '12 at 11:22
  • Launch your command with "php -c /path/to/your/php.ini", or use Zend Server Community Edition, or have you try "locate php.ini" to find php.ini file – acubens Sep 22 '12 at 11:40
6

I had the same problem, and it's true there is a command line, and MAMP/Native Mac PHP service running on Yosemite, and while I was trying to follow the directions on this page non of them seemed to work for me.

When I ran php command:

$ php -i | grep 'Configuration File'
Configuration File (php.ini) Path => /etc
Loaded Configuration File => <em>(Blank)</em>

I realized that the php.ini that the CLI was using, was actually php.ini.default file. I created a symbolic link to that file as the php.ini and everything worked.

My-MacPro:/etc/$ ln -s php.ini.default php.ini

B. Clincy
  • 126
  • 1
  • 4
  • 1
    This helped me out, I found that my php install (from brew) was using a different php.ini file than I expected, and therefore not picking up the value. Ended up making a symlink to /etc/php.ini to avoid this issue in the future – crobicha Jul 23 '15 at 22:41
4

I did follow your answers, but in my case none of them worked. I decided to go change the date_default_timezone_get() in the logger.php file.

I replaced with my timezone setting ("Europe/Berlin"), and all went well !

Old school solution but still a solution.

Franck
  • 41
  • 1
  • 1
4

I had the exact same problem with my SF2 installation.

To fix this just go into your php.ini file at /etc/php.ini and change your file to look like this (adjust your timezone to suit your local timezone):

;;;;;;;;;;;;;;;;;;; ; Module Settings ; ;;;;;;;;;;;;;;;;;;;

[Date] 
; Defines the default timezone used by the date functions 
; http://www.php.net/manual/en/datetime.configuration.php#ini.date.timezone 
date.timezone = Europe/London
crmpicco
  • 16,605
  • 26
  • 134
  • 210
3

Your default php.in in Mac OSX is located at /etc/php.ini which is exactly the same than the /private/etc/php.ini file.

You should know that you have the possibility of using two php version running in parallel. I had this issue 'cause I was using the native mac osx php, however I had to install a php package through homebrew, then I got the other version of php through homebrew. though I had the time zone already configured in my php.ini file at /etc/php.ini, I still had the same problem, so I run:

php -i | grep 'Configuration File'

in order to configure the correct file, so I got:

Configuration File (php.ini) Path => /usr/local/etc/php/5.3
Loaded Configuration File => /usr/local/etc/php/5.3/php.ini
PHP Warning:  Unknown: 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/Buenos_Aires' for 'ART/-3.0/no DST' instead in Unknown on line 0

Then I knew I had to edit the /usr/local/etc/php/5.3/php.ini file.

After that, It all went right. I had not that issue any more.

I hope it helps you to solve that.

Emilio Gort
  • 3,475
  • 3
  • 29
  • 44
  • Yes, this is the answer! I have MAMP installed. I was tried for about an hour editing `/etc/php.ini` and `/private/etc/php.ini`, but I needed to edit `/usr/local/etc/php/5.5/php.ini` - then these Symfony2 errors went away. – Eamorr May 27 '15 at 13:36
1

Usually, there are separate php.ini files for CLI and Apache. Make sure you've edited the needed one.

Elnur Abdurrakhimov
  • 44,533
  • 10
  • 148
  • 133
  • i have tried finding them with locate php.ini and the phpinfo() in MAMP. The right one is loaded and edited by me. How do I change the path of php.ini manually ? – Radolino Sep 22 '12 at 11:17
1

By default Mac uses in the console the PHP located at:

/private/etc/php.ini

You should use this one because MAMP always unset the timezone variable and you would always get that error.

andresgz
  • 39
  • 4
1

I had a similar problem on OS X 10.9. The problem in my case was the absence of a php.ini file in /etc. I solved the problem by creating that php.ini file with the contents:

date.timezone = Europe/Athens
Pankrates
  • 3,074
  • 1
  • 22
  • 28
  • I insist that the way MAC OS along with MAMP uses php/mysql is crappy. Took me years to understand and fix. – Radolino Nov 07 '13 at 07:29