Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Warning: date_default_timezone_get() installing Symfony

Tags:

php

symfony

I'm trying to install Symfony on XAMPP and I keep getting numerous errors.

[Symfony\Component\Debug\Exception\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 
/Applications/XAMPP/xamppfiles/htdocs/vendor/monolog/monolog/src/Monolog/Logger.php line 233 

and then

Script Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache handling the post-
install-cmd event terminated with an exception

and finally

[RuntimeException]                                                         
An error occurred when executing the "'cache:clear --no-warmup'" command.

I've tried changing the date.timezone in my php.ini file and using the date_default_timezone_set() function in the command line before trying to install it and nothing seems to work.

I've been staring at it for a while so any help is appreciated

like image 917
dabecks Avatar asked Jun 16 '14 20:06

dabecks


3 Answers

If you can't set it correctly in your php.ini for some reason then you can set it as the first thing in your AppKernel, like so..

class AppKernel extends Kernel
{
    public function __construct($environment, $debug)
    {
        date_default_timezone_set('Europe/London');
        parent::__construct($environment, $debug);
    }

    public function registerBundles()
    {
        $bundles = array(
            ....
        );
    }

    ....
}
like image 172
qooplmao Avatar answered Nov 07 '22 23:11

qooplmao


Found a similar way to fix this issue while other didn't.

  1. First check where the CLI php.ini is located:

    php -i | grep "php.ini"

  2. In my case I ended up with : Configuration File (php.ini) Path => /etc

  3. Then cd .. all the way back and cd into /etc, do ls in my case php.ini didn't show up, only a php.ini.default

  4. Now, copy the php.ini.default file named as php.ini:

    sudo cp php.ini.default php.ini

  5. In order to edit, change the permissions of the file:

    sudo chmod ug+w php.ini

    sudo chgrp staff php.ini

  6. Open directory and edit the php.ini file:

    open .

    Tip: If you are not able to edit the php.ini due to some permissions issue then copy 'php.ini.default' and paste it on your desktop and rename it to 'php.ini' then open it and edit it following step 7. Then move (copy+paste) it in /etc folder. Issue will be resolved.

  7. Search for [Date] and make sure the following line is in the correct format:

    date.timezone = "Europe/Amsterdam"

like image 22
Peter Avatar answered Nov 07 '22 21:11

Peter


It is very very common for WAMP/XAMPP and other stacks to have use of multiple php.ini files - one for cli and one for web.

Since you're expiriencing the error from CLI try the following:

php -i | grep "php.ini"

this will output location of php.ini used for cli. Edit the date.timezone there.

As for the web mode, create a file foo.php within your "web" directory of symfony containing only"

<?php phpinfo(); ?>

And, again, find the location of php.ini used and edit the date.timezone.

like image 3
Jovan Perovic Avatar answered Nov 07 '22 21:11

Jovan Perovic