I'm installing Symfony on my Ubuntu system, everything was going fine until the very last moment when I was met with a screen that said:
ContextErrorException: 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-test/app/cache/dev/classes.php line 5107
in /var/www/symfony-test/app/cache/dev/classes.php line 5107
at ErrorHandler->handle('2', '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.', '/var/www/symfony-test/app/cache/dev/classes.php', '5107', array('level' => '100', 'message' => 'Notified event "kernel.exception" to listener "Symfony\Component\HttpKernel\EventListener\ProfilerListener::onKernelException".', 'context' => array()))
at date_default_timezone_get() in /var/www/symfony-test/app/cache/dev/classes.php line 5107
at Logger->addRecord('100', 'Notified event "kernel.exception" to listener "Symfony\Component\HttpKernel\EventListener\ProfilerListener::onKernelException".', array()) in /var/www/symfony-test/app/cache/dev/classes.php line 5193
at Logger->debug('Notified event "kernel.exception" to listener "Symfony\Component\HttpKernel\EventListener\ProfilerListener::onKernelException".') in /var/www/symfony-test/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Debug/TraceableEventDispatcher.php line 246
at TraceableEventDispatcher->preListenerCall('kernel.exception', array(object(ProfilerListener), 'onKernelException')) in /var/www/symfony-test/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Debug/TraceableEventDispatcher.php line 448
at TraceableEventDispatcher->Symfony\Component\HttpKernel\Debug\{closure}(object(GetResponseForExceptionEvent))
at call_user_func(object(Closure), object(GetResponseForExceptionEvent)) in /var/www/symfony-test/app/cache/dev/classes.php line 1667
at EventDispatcher->doDispatch(array(object(Closure), object(Closure)), 'kernel.exception', object(GetResponseForExceptionEvent)) in /var/www/symfony-test/app/cache/dev/classes.php line 1600
at EventDispatcher->dispatch('kernel.exception', object(GetResponseForExceptionEvent)) in /var/www/symfony-test/app/cache/dev/classes.php line 1764
at ContainerAwareEventDispatcher->dispatch('kernel.exception', object(GetResponseForExceptionEvent)) in /var/www/symfony-test/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Debug/TraceableEventDispatcher.php line 139
at TraceableEventDispatcher->dispatch('kernel.exception', object(GetResponseForExceptionEvent)) in /var/www/symfony-test/app/bootstrap.php.cache line 2870
at HttpKernel->handleException(object(ContextErrorException), object(Request), '1') in /var/www/symfony-test/app/bootstrap.php.cache line 2823
at HttpKernel->handle(object(Request), '1', true) in /var/www/symfony-test/app/bootstrap.php.cache line 2947
at ContainerAwareHttpKernel->handle(object(Request), '1', true) in /var/www/symfony-test/app/bootstrap.php.cache line 2249
at Kernel->handle(object(Request)) in /var/www/symfony-test/web/app_dev.php line 28
After many hours of trying ideas in other threads, editing php.ini and classes.php to something that might work, I have gotten absolutely nowhere! Has anyone else had this problem
EDIT! The plot thickens!
So I cleared the cache via the terminal, and I got an error relating to classes.php, which apparently is to do with permissions, so I sorted that as per the instructions on Symfony's site, and now guess what's happened? We're back to square one, only this time I can't clear my cache to make it go away. Yet, after I do clear the cache instead of it being php.ini, it's instead Logger.php, locating in /vendor/monolog/monolog/src/Monolog, but then after a refresh it's back to php.ini
SOLVED
I feel like a bit of an idiot here! I didn't realise .ini files used ';' to indicate a comma, therefore every line in my php.ini file was a comment. I removed the semi-colon and now it all works
Set the timezone string in the php.ini. I strongly recommend that your server be configured to use UTC and then your setting should be:
date.timezone = UTC
Restart your web server
Just to be double safe:
php app/console cache:clear
You might also have an issue finding the right php.ini. Check these directories:
/etc/php5/apache2
/etc/php5/cli
Ubuntu tends to separate out php.ini's for the command line vs mod_php, vs cgi, and there are directories for each. If you're not sure which php.ini is being loaded, there is php -i for the cli and the phpinfo(); program you can put in a quick script under your webroot. Each will provide you information on the location of the php.ini that is being loaded.
Set the date/timezone in php.ini but make sure you clear your cache before running your code again. Symfony 2 cache clear is required as the classes.php is created by Symfony. From the main project dir app/console cache:clear --env=dev
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.