4

I'm trying to set up a symfony 2.7 based app on a shared server and have no permission to change the php.ini.

Executing: php app/console doctrine:schema:drop --force

Outputs this warnings/errors:

PHP Warning:  Uncaught exception 'Symfony\Component\Debug\Exception\ContextErrorException' with message '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.'
0 [internal function]: Symfony\Component\Debug\ErrorHandler-    >handleError(2, 'date_default_ti...', '/path...', 272, Array)
1 /domain.com/app/vendor/monolog/monolog/src/Monolog/Logger.php(272): date_default_timezone_get()
2 /domain.com/app/vendor/monolog/monolog/src/Monolog/Logger.php(481): Monolog\Logger->addRecord(100, 'Notified event ...', Array)
3 /domain.com/app/vendor/symfony/ in /domain.com/app/vendor/monolog/monolog/src/Monolog/Logger.php on line 272
PHP Fatal error:  date_default_timezone_get(): Timezone database is corrupt - this should *never* happen! in /domain.com/app/vendor/monolog/monolog/src/Monolog/Logger.php on line 272
PHP 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 /domain.com/app/vendor/monolog/monolog/src/Monolog/Logger.php on line 272
PHP Fatal error:  date_default_timezone_get(): Timezone database is corrupt - this should *never* happen! in /domain.com

I tried this:

class AppKernel extends Kernel
{
    public function init()
    {
        date_default_timezone_set( 'Europe/Berlin' );
        parent::init();
    }
}

Outputs the next error:

PHP Fatal error:  Uncaught exception 'Symfony\Component\Debug\Exception\ContextErrorException' with message 'Notice: date_default_timezone_set(): Timezone ID 'Europe/Berlin' is invalid' in /domain.com/app/app/AppKernel.php:42

According to php.net Europe/Berlin is a valid identifier.

According to this answer timezonedb.so should be installed (it's not).

According to Symfony 1.4 docs it's possible to set default_timezone in the settings.yml. I cannot find a similar config for >= 2.0. Edit: "Unlike Symfony 1.4, there isn’t a default_timezone config parameter to set the default timezone in Symfony2. [...]" (source)

Any ideas, how to solve the problem?

Thanks in advance!

Community
  • 1
  • 1
Mr. B.
  • 8,041
  • 14
  • 67
  • 117
  • The error message arises because the default timezone has not been set in the php.ini file. Please have a look at this answer. http://stackoverflow.com/questions/24251793/warning-date-default-timezone-get-installing-symfony – Praveesh Aug 14 '15 at 19:33
  • @Praveesh as mentioned above, I tried this solution already and I'm unfortunately still not allowed to edit the php.ini. – Mr. B. Aug 14 '15 at 19:48
  • 1
    Simply change your hoster. – Emii Khaos Aug 15 '15 at 10:18
  • @Paziツ I'm trying to avoid it, but I guess, that's the only solution. – Mr. B. Aug 16 '15 at 09:38
  • That's the best solution. A hoster which is such restricting it not worth the trouble.. – Emii Khaos Aug 16 '15 at 10:39

2 Answers2

15

it is recommended that you set the timezone in php.ini but if you are in shared environment or if you don't have access to it for some reason you can add this in app/AppKernel.php

class AppKernel extends Kernel
{
        public function __construct($environment, $debug)
        {
            date_default_timezone_set( 'America/Detroit' );
            parent::__construct($environment, $debug);
        }
}
wonde
  • 1,181
  • 10
  • 20
1

At less for me @wonde answer didn't work i don't know why, this worked for me

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

Adding this line in your files :

/web/app_dev.php

/web/app.php

and if that doesnt work add in your kernel too.

That fix the problem for me !

Carlos Delgado
  • 2,930
  • 4
  • 23
  • 49