Php – How to hanfdle PHP 5.3.2 timezone bug

apache-2.2PHP

on server i have php 5.3.2.

if i want to run simple php script, like this :

<?php echo date('Y'); ?>

…it gives me following errors:

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 'Europe/Berlin' for 'CEST/2.0/DST' instead in /htdocs/index.php on line 9 Fatal error: date(): Timezone database is corrupt – this should never happen! in /htdocs/index.php on line 9

Timezone in php.ini is defined as Europe/London

I'm ALWAYS getting that error, despite I define or not date_default_timezone_set('UTC'), or Europe/London, or whatever…

I tried to edit /etc/init.d/httpd file, but i don't have permissions (due to selinux?)

please help…

Best Answer

That's not a PHP bug - it's telling you something is wrong, and you need to correct it.

I notice the line Timezone database is corrupt - this should never happen! - try the following command in your shell and restart Apache: apt-get install tzdata.

If it's still broken after that (or you already have that package), create a new PHP file with the following contents and load it up in a browser: <?php phpinfo(); ?>.

Look for Loaded Configuration File and check that is the php.ini file you are editing.

Open that php.ini file and look for the line beginning date.timezone. Make sure the timezone you are selecting is enclosed in quotes - the one I use is as follows: date.timezone = "Europe/London".

Once you've modified and saved php.ini, you must reload Apache for the change to take effect.

Related Topic