I got this error when I requested to update the PHP version from 5.2.17 to PHP 5.3.21 on the server.
If you are using CodeIgniter and can't change php.ini, I added the following to the beginning of index.php:
date_default_timezone_set('GMT');
In my particular case, I have PHP configured to use PHP-FPM (FastCGI Process Manager). When executing phpinfo()
from CLI I saw correct timezone that I had set in the php.ini, however it was still incorrect in the browser and causing my code to fail. I simply needed to restart the php-fpm
service on the server.
service rh-php56-php-fpm restart
You may also need to restart the httpd
service if you edited the php.ini
service httpd restart
If these are not your options
php.ini
.date_default_timezone
call.Instead of date
you could use gmdate
.
I have used gmdate( "Y" )
when I needed a year for a copyright snipplet.
If you cannot modify your php.ini configuration, you could as well use the following snippet at the beginning of your code:
date_default_timezone_set('Africa/Lagos');//or change to whatever timezone you want
The list of timezones can be found at http://www.php.net/manual/en/timezones.php.
There are two options for the resolve this
First, change into the php.ini file and put default timezone
date.timezone = "America/New_York"
Once, you have set the timezone in php.ini restart the server
Secondly, Change the run time assign time zone based on your need
date_default_timezone_set('America/New_York');
This answer above from CtrlX is the correct answer, but it may not work completely. I added this line to my php.ini file:
date.timezone = "America/Los_Angeles"
but it did not remove the PHP error for all my files because some of my PHP scripts are in subfolders. So I had to edit .htaccess file to setup php.ini to be used recursively (in subfolders):
suphp_configpath /home/account_name/public_html
where account_name is your cpanel account name and public_html is the folder your php.ini file is in.