PHP Configuration: It is not safe to rely on the system's timezone settings

PhpTimezone

Php Problem Overview


Here a weird one. I just upgrade to php 5.3.0 and since the upgrade I'm getting the following warning:

> Warning: getdate() [function.getdate]: > 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/Chicago' for > 'CST/-6.0/no DST'

After looking in various forums, everybody says that to solve the problem, all you have to do is edit the date zone in the php.ini and restart Apache.

It did not work for me.

I tried

date.timezone="America/New_York"

date.timezone=America/New_York

date.timezone="US/Central"

Restarted apache after I made the change.

Since I still have the older version of php install, I even made sure that I'm editing the php.ini that the current version of php uses at the time to load

/usr/local/php5/lib/php.ini

Still getting the warning.

Any suggestions?

Thanks for taking the time.

Php Solutions


Solution 1 - Php

Tchalvak, who commented on the original question, hit the nail on the head for me. I've been editing (I use Debian):

/etc/php5/apache2/php.ini

...which had the correct timezone for me and was the only .ini file being loaded with date.timezone within it, but I was receiving the above error when I ran a script through Bash. I had no idea that I should have been editing:

/etc/php5/cli/php.ini

as well. (Well, for me it was 'as well', for you it might be different of course, but I'm going to keep my Apache and CLI versions of php.ini synchronised now).

Solution 2 - Php

Solution 3 - Php

I happened to have to set up Apache & PHP on two laptops recently. After much weeping and gnashing of teeth, I noticed in phpinfo's output that (for whatever reason: not paying attention during PHP install, bad installer) Apache expected php.ini to be somewhere where it wasn't.

Two choices:

  1. put it where Apache thinks it should be or
  2. point Apache at the true location of your php.ini

... and restart Apache. Timezone settings should be recognized at that point.

Solution 4 - Php

Open your .htaccess file , add this line to the file, save, and try again :

php_value date.timezone "America/Sao_Paulo"

This works for me.

Solution 5 - Php

try this, it works for me.

date_default_timezone_set('America/New_York');

In the actual file that was complaining.

Solution 6 - Php

Check for syntax errors in the php.ini file, specially before the Date paramaters, that prevent the file from being parsed correctly.

Solution 7 - Php

Please modify your index.php as follows:

require_once($yii);
$app = Yii::createWebApplication($config);
Yii::app()->setTimeZone('UTC');
$app->run();

Solution 8 - Php

Obviously I'm a little out of season on this question but for the benefit of the next sufferer: I just had this problem and in my case (in contrast to OP who tried the same without success) the fix was to revise php.ini, changing

date.timezone = America/New York

to

date.timezone = America/New_York

That is adding the underscore.

Solution 9 - Php

I modified /etc/php.ini

[Date] ; Defines the default timezone used by the date functions ; http://php.net/date.timezone date.timezone =('Asia/kolkata')

and now working fine.

Vipin Pal

Solution 10 - Php

You may have forgot to remove the semicolon to uncomment that line. For the date.timezone = "US/Central" line, be sure that there's no semicolon in front of that line.

Solution 11 - Php

I found, bizarrely, that I could fix the errors by placing the timezone declaration at the TOP of my php.ini file.

It was already in my php.ini. Twice, actually. And I was pulling my hair out because everyone was saying there must be another ini being loaded... There wasn't.

Hope this can save someone else the time/hair loss.

Solution 12 - Php

also you can try this

date.timezone = <?php date('Y'); ?>

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionOle MediaView Question on Stackoverflow
Solution 1 - PhpVaughanyView Answer on Stackoverflow
Solution 2 - PhpcichyView Answer on Stackoverflow
Solution 3 - PhpGarvinView Answer on Stackoverflow
Solution 4 - PhpcodexView Answer on Stackoverflow
Solution 5 - PhpselangkView Answer on Stackoverflow
Solution 6 - PhpamercaderView Answer on Stackoverflow
Solution 7 - PhpAshutosh NigamView Answer on Stackoverflow
Solution 8 - Phpuser1613163View Answer on Stackoverflow
Solution 9 - PhpVipin PalView Answer on Stackoverflow
Solution 10 - PhpSirNikkolasView Answer on Stackoverflow
Solution 11 - PhpSoft BulletsView Answer on Stackoverflow
Solution 12 - PhpmahamiView Answer on Stackoverflow