Setting PHP timezone in php.ini

During the work with Symfony framework, I received the following warning:

Warning: date_default_timezone_get(): 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 the timezone 'UTC' for now, but please set date.timezone to select your timezone. in /var/www/symfony/app/cache/prod/classes.php on line 5009

In fact, there is nothing to worry about or unusual - this was caused by updating PHP to version 5.4, and since the new version was installed next to the old one with new configs, it was necessary to configure the PHP timezone in php.ini again. First, we need to find out which timezone we are in. More precisely, how it should be specified in the PHP config. You can do this here:

Open the php.ini file. For Debian, do this:

nano /etc/php5/apache2/php.ini 

Using search, look for ;date.timezone (if there is no such line - then add it manually). We see that the line is commented out:

;date.timezone =

Uncomment it and set the locale, for example:

date.timezone = Europe/Kiev

Save the file. This can also be done in the php script or .htaccess file (for example, if you are on shared hosting - you cannot edit php.ini). In the first case, it is enough to write in the script


This method is also suitable if you wanted to make the user happy and display the time depending on his location.

In the second case, add to .htaccess (if only php is not in fastcgi mode)

php_value date.timezone 'Europe/Kiev'

In order for the changes to take effect, you need to reload the Apache configuration. Or restart it completely. For Debian, SysVinit:

service apache2 reload


systemctl reload apache2

This method also works with php 5.5, 5.6, and 7.*.