Monday, April 23, 2012

Linux: phpinfo() system’s timezone error date.timezone

I'm getting the following errors in my log file whenever I use phpinfo() function:
[10-Jan-2011 18:39:08] PHP Warning: phpinfo(): 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' instead in /home/servers/http/dev/testpc.php on line 2
How do I fix this problem under UNIX / Linux php running Apache or lighttpd web server?

This problem or warning can be easily fixed by editing the /etc/php.ini file. Open a command-line terminal (select Applications > Accessories > Terminal), and then type the following commands or login using ssh to the remote server. First find out your timezone from /etc/sysconfig/clock file, enter:
# cat /etc/sysconfig/clock
ZONE="America/Chicago"
UTC=true
ARC=false

Edit /etc/php.ini, enter:
# vi /etc/php.ini
Make the changes as follows, enter (find date.timezone and update it as follows):
 
date.timezone="America/Chicago"
 
Save and close the file. Restart the Apache server:
# service httpd restart
If you are using lighttpd type the following to restart it:
# service lighttpd restart
Note: If you don't have access to the /etc/php.ini file, add the following line in your php file before any date related functions:
 
<?php
....
....
date_default_timezone_set("America/Chicago");
phpinfo();
...
..
?>
 

No comments:

Post a Comment