Symfony 2 default timezone not set cause fatal error in production environment

Symfony 2 default timezone not set cause fatal error in production environment

This issue happens when the php.ini property date.timezone is not defined or has a default value. It's very recommendable to change this value on the php.ini file of your server.

Solution

Change the date.timezone property in the php.ini file for a valid value, for example

date.timezone = Europe/Berlin;

If you don't know the location of the php.ini file of your server, you can use the following code to know the path :

echo get_cfg_var('cfg_file_path');
// will output something like :
// var/www/blabla/php.ini

If for any reason, you can make changes to the php.ini file (which is highly recommendable), then you can solve your problem quickly adding the following line to the AppKernel.php file :

date_default_timezone_set( 'Europe/Berlin' );

If the problem persist, you can add this line in the app_dev.php and app.php file.

Note: In some servers the same feature may not work, if is your case try using the following adding too the following line.

ini_set('date.timezone', 'Europe/Berlin');

Obviously change the Zone variable according to your location (America,Europe etc ...).

Become a more social person