I recently upgraded a CentOS Linux servers PHP from 5.2.X to 5.3.X and ran into a couple minor issues along the way. One of the issues was the fact that one of my applications was complaining about PHP’s date function by letting me know that it could not rely on the system’s timezone setting. Fixing this problem is extremely easy and can most likely be resolved by a quick edit to the servers php.ini file as described in detail below.
Application Error After PHP 5.2.X Upgrade To PHP 5.3.X:
- Type: Warning (2)
- Description: 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/Chicago' for 'CST/-6.0/no DST' instead
- Request: GET /directory/index.php?fuse=admin&view=Login
- Script: var/www/directory/admin/views/Login.php
- Line Number: 25
- Stack:
- var/www/directory/newedge/classes/NE_Controller.php (167) : login::dispatch
- var/www/directory/newedge/front.php (76) : ne_controller::processview
- var/www/directory/index.php (3) : unknown
As you can see above the application is throwing an error about the PHP date function. All that needs to be done is to modify the date.timezone setting within php.ini as described below. First locate the proper timezone for the server which on CentOS can be done by looking in the “/usr/share/zoneinfo/” directory. In this instance I needed to set the date.timezone to “America/Louisville” as shown in the below output. On CentOS Linux the php.ini file is located in the /etc/ directory.
Original Blank php.ini date.timezone Setting:
- ;;;;;;;;;;;;;;;;;;;
- ; Module Settings ;
- ;;;;;;;;;;;;;;;;;;;
- [Date]
- ; Defines the default timezone used by the date functions
- ; date.timezone =
We will be uncommenting the date.timezone setting in the php.ini configuration file and adding the America/Louisville timezone as displayed in the below example.
Modified PHP 5.3 php.ini With date.timezone Set:
- ;;;;;;;;;;;;;;;;;;;
- ; Module Settings ;
- ;;;;;;;;;;;;;;;;;;;
- [Date]
- ; Defines the default timezone used by the date functions
- date.timezone = "America/Louisville"
After saving the modification to php.ini restart your web server which in this example happened to be Apache on CentOS Linux and is restarted as shown in the below example.
Restart Apache For New php.ini Settings To Take:
- [root@dev php.d]# /etc/init.d/httpd restart
- Stopping httpd: [ OK ]
- Starting httpd: [ OK ]
After restarting Apache the web application was working without issue.
Thanks for any other informative website. Where else
could I am getting that type of info written in such a perfect approach?
I’ve a venture that I am just now operating on, and I’ve been at
the glance out for such info.