当我请求在服务器上将PHP版本从5.2.17更新到PHP 5.3.21时,我得到了这个错误。

<div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

<h4>A PHP Error was encountered</h4>

<p>Severity: Warning</p>
<p>Message:  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 'America/New_York' for 'EDT/-4.0/DST' instead</p>
<p>Filename: libraries/Log.php</p>
<p>Line Number: 86</p>

</div>
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 'America/New_York' for 'EDT/-4.0/DST' instead in /filelocation right here/system/libraries/Log.php on line 86

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 'America/New_York' for 'EDT/-4.0/DST' instead in /filelocation right here/system/libraries/Log.php on line 99
<div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

<h4>A PHP Error was encountered</h4>

<p>Severity: Warning</p>
<p>Message:  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 'America/New_York' for 'EDT/-4.0/DST' instead</p>
<p>Filename: libraries/Log.php</p>
<p>Line Number: 99</p>

</div>

当前回答

你可以在你的.htaccess文件中设置时区

php_value date.timezone UTC

其他回答

对于docker用户: 在你的项目中创建一个本地时区。ini文件,在docker-compose.yml中设置配置,

    volumes:
        - "./docker/config/timezone.ini:/usr/local/etc/php/conf.d/timezone.ini"

timezone.ini

    date.timezone=Australia/Sydney

解决这个问题有两种方法

首先,在php.ini文件中输入默认时区

date.timezone = "America/New_York"

在php.ini中设置好时区后,重新启动服务器

其次,改变运行时间 根据您的需要分配时区

date_default_timezone_set('America/New_York');

我在us-west-2(俄勒冈州)地区托管我的EC2和S3存储桶。当我调用$s3client->listBuckets()来列出我的php中现有的桶时,我得到了异常-“未捕获的异常'异常'与消息'DateTime::__construct():依赖系统的时区设置是不安全的…”。 我做了以下更改,使其工作。分享这些细节,以防有人面临类似的问题,以上任何答案都没有帮助。

Based on documentation @ AWS Configuring Network Time Protocol (NTP), I confirmed ntpd service status is fine by running ntpstat command. If you get error, this link helps you to know what is going wrong. Opened /etc/php.ini file (some may have it in different path based on version of php installed) and found that date.timezone was not set to any value and also it was commented by default. I un-commented by removing ';' before this line and set its value to "UTC" and saved the file. Restarted http and ntp daemons using sudo service httpd restart and sudo service ntpd restart commands.

在此之后,我能够成功地列出桶没有任何例外。希望这能有所帮助。

如果你不能访问php.ini文件,在你的域或子目录的根目录下创建或编辑一个。htaccess文件,并添加这个(由cpanel生成):

<IfModule mime_module>
AddType application/x-httpd-ea-php56 .php .php5 .phtml
</IfModule>

<IfModule php5_module>
php_value date.timezone "America/New_York"
</IfModule>

<IfModule lsapi_module>
php_value date.timezone "America/New_York"
</IfModule>

在我的特殊情况下,我有PHP配置为使用PHP- fpm (FastCGI进程管理器)。当从CLI执行phpinfo()时,我看到了我在php.ini中设置的正确时区,但在浏览器中仍然不正确,导致我的代码失败。我只需要在服务器上重新启动php-fpm服务。

service rh-php56-php-fpm restart

如果您编辑了php.ini,则可能还需要重新启动httpd服务

service httpd restart