-4

I was doing a bit of learning about PHP from an online school and was following along and was introduced to this message in terminal and wanted to know if anyone can help me understand why this is happening. Is this because of a setting I have on my local computer or is this a setting somewhere else because the instructor for this course didn't write any additional code for this.

PHP Warning:  date(): 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 the timezone 'UTC' for now, 
but please set date.timezone to select your timezone.
user3732216
  • 1,579
  • 8
  • 29
  • 54
  • It's a setting in the php.ini file on your server where the php code is executing – Mark Baker Aug 27 '16 at 23:19
  • If I"m running this from terminal where should I find the php.ini file? – user3732216 Aug 27 '16 at 23:20
  • 3
    The error explains exactly why you're seeing that error and even how to fix it if you bother to read it. – Sherif Aug 27 '16 at 23:21
  • @Sherif I don't know where hte php.ini file resides. – user3732216 Aug 27 '16 at 23:21
  • 2
    If you are learning to program, then the single most important piece of advice that you can receive is this: Read the error messages. Strive to understand them. They almost always tell you specifically what's going on. And, if you had Googled this, you would have found multiple answers already. – random_user_name Aug 27 '16 at 23:22
  • 1
    From the command line use `php --ini` to find your php.ini file, but again, the error message provides additional options notice "_or the `date_default_timezone_set()` function_" – Sherif Aug 27 '16 at 23:23
  • 1
    This is actually a duplicate of http://stackoverflow.com/questions/16765158/date-it-is-not-safe-to-rely-on-the-systems-timezone-settings – Sherif Aug 27 '16 at 23:26
  • Also, possibly http://stackoverflow.com/questions/2750580/how-to-find-the-php-ini-file-used-by-the-command-line – Sherif Aug 27 '16 at 23:27
  • As it turned out I still had php version 5.* installed on my local machine so I installed php7 on with homebrew and doing that erased the error. – user3732216 Aug 27 '16 at 23:52
  • Possible duplicate of [PHP DateTime throws timezone warning even though date.timezone set](http://stackoverflow.com/questions/20061861/php-datetime-throws-timezone-warning-even-though-date-timezone-set) – Tosho Trajanov Aug 28 '16 at 08:32

1 Answers1

1

Find the php.ini file and add the appropriate value under date.timezone

The values are here: http://www.php.net/manual/en/datetime.configuration.php#ini.date.timezone

To find out where your php.ini file is, use php -i on the command line, or <?php phpinfo(); through the web server. The Loaded Configuration file should give you the full path to the php.ini file.

Restart the web server after updating the php.ini file.

user2182349
  • 9,569
  • 3
  • 29
  • 41