I got this error when I requested to update the PHP version from 5.2.17 to PHP 5.3.21 on the server.
I am hosting my EC2 and S3 bucket in us-west-2 (Oregon) region. When I was calling $s3client->listBuckets()
to list existing buckets in my php, I was getting exception - "Uncaught exception 'Exception' with message 'DateTime::__construct(): It is not safe to rely on the system's timezone settings...".
I made below changes to make it work. Sharing these details in case someone is facing similar issue and any of above answers have not helped.
ntpstat
command. If you get error, this link helps you to know what is going wrong.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.sudo service httpd restart
and sudo service ntpd restart
commands.After this I am able to list buckets successfully without any exception. Hope this helps.
A quick solution whilst your rectify the incompatibilities, is to disable error reporting in your index.php
file:
Insert the line below into your index.php below define( ‘_JEXEC’, 1 );
error_reporting( E_ERROR | E_PARSE | E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR |
E_COMPILE_WARNING );
For docker user: Create a local timezone.ini file in your project, set up the config in docker-compose.yml,
volumes:
- "./docker/config/timezone.ini:/usr/local/etc/php/conf.d/timezone.ini"
timezone.ini
date.timezone=Australia/Sydney
You probably need to put the timezone in a configuration line in your php.ini
file. You should have a block like this in your php.ini file:
[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = America/New_York
If not, add it (replacing the timezone by yours). After configuring, make sure to restart httpd (service httpd restart
).
Here is the list of supported timezones.
@Justis pointed me to the right direction, but his code did not work for me. This did:
// set the default timezone if not set at php.ini
if (!date_default_timezone_get('date.timezone')) {
// insert here the default timezone
date_default_timezone_set('America/New_York');
}
Documentation: http://www.php.net/manual/en/function.date-default-timezone-get.php
This solution is not only for those who does not have full system access. It is necessary for any script when you provide it to anyone else but you. You never know on what server the script will run when you distribute it to someone else.
I had this error running php-fpm in a chroot jail. I tried creating etc/php.ini and /usr/share/zoneinfo in the chroot directory, but it just didn't work. I even tried strace-ing the php-fpm daemons to see what file they were missing - nothing jumped out.
So in case Google brings you here because you get this error when using php-fpm configured for chroot, you can probably fix it by adding this line to /etc/php-fpm.d/www.conf
in the ENV section:
env[TZ] = America/New_York
A php-fpm restart is normally required for it to take effect. Hope this helps somebody out there.