If you are facing a problem with the timezone when deploying your symfony 2 project to production, this may help you.

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 ...).


Senior Software Engineer at Software Medico. Interested in programming since he was 14 years old, Carlos is a self-taught programmer and founder and author of most of the articles at Our Code World.

Sponsors