I have tried everything under the sun to enable the ability to run this command after installing Symfony2.
php app/console cache:clear --no-warmup OR php app/console cache:clear
I get this error every time:
[ErrorException] 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/rt/vendor/jms/serializer-bundle/JMS/SerializerBundle/DependencyInjection Configuration.php line 66
On line 66:
->scalarNode('default_timezone')->defaultValue(date_default_timezone_get())->end()
I've tried this Stack Post:
Warning: date_default_timezone_get():
I've tried to edit ALL php.ini files, phpinfo() for XAMPP shows:
date/time support enabled
"Olson" Timezone Database Version 2013.4
Timezone Database internal
Default timezone UTC
$ php --ini shows
Configuration File (php.ini) Path: /etc (I edited this one as well)
php.ini shows
date.timezone = UTC
I cannot run php composer.phar install without the ability to get past this stupid date_default_timezone_set() error.
Please help, its been 2 haggling days trying to get this fixed and I am at my wits end.
Thanks!
I've solved this issue adding this code to the app/AppKernel.php file:
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;
class AppKernel extends Kernel {
public function init() {
// Change timezone
date_default_timezone_set('America/Caracas');
parent::init();
}
// ......
}
A good option is also to add the following into the virtualhost file (if applicable)
php_value date.timezone America/Caracas
Add the below in your virtualhost file as suggested above
php_value date.timezone America/Caracas
You can also have the same in the .htaccess file in the web folder of your symfony2 instead.
Check the php.ini under both
/etc/php5/apache2/ ( for apache2 )
and
/etc/php5/cli/ ( for command line )
You can add a default timezone to your php.ini
http://www.inmotionhosting.com/support/website/php/setting-the-timezone-for-php-in-the-phpini-file
Don't forget to restart the server
Related
Just started my first symfony2 project, and after installation on running http://127.0.0.1/inventory/web/config.php i got below message.
This script will guide you through the basic configuration of your project. You can also do the same by editing the ‘app/config/parameters.yml’ file directly.
**MAJOR PROBLEMS**
Major problems have been detected and must be fixed before continuing:
Set the "date.timezone" setting in php.ini* (like Europe/Paris).
* Changes to the php.ini file must be done in "/etc/php5/apache2/php.ini".
I have set date.timezone = "Asia/Karachi" in following files
/etc/php5/cli/php.ini
/etc/php5/apache2/php.ini
and this too in AppKernel.php
public function init()
{
// get rid of Warning: date_default_timezone_get(): It is not safe to rely on the system's timezone
date_default_timezone_set( 'Asia/Karachi' );
parent::init();
}
but still the same error.
however, when i run this php -i | grep "timezone"command on console i got this,
Default timezone => Asia/Karachi
date.timezone => Asia/Karachi => Asia/Karachi
More on running phpinfo() function on test.php file i got this,
I've created a new Symfony project with
$ symfony new my_project
This is now in a folder called /Symfony/my_project
At this point I get this:
PHP Warning: date(): 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 phar:///usr/local/bin/symfony/src/Symfony/Installer/NewCommand.php on line 262
✕ Symfony 2.7.3 was successfully installed but your system doesn't meet its
technical requirements! Fix the following issues before executing
your Symfony application:
* date.timezone setting must be set
> Set the "date.timezone" setting in php.ini* (like Europe/Paris).
Than says
Then, you can:
* Change your current directory to /Users/[username]/Dropbox/private/dbx/Symfony/my_project
* Configure your application in app/config/parameters.yml file.
* Run your application:
1. Execute the php app/console server:run command.
2. Browse to the http://localhost:8000 URL.
At this point I don't know where is the php.ini file in Yosemite. I've looked around and found an answer on this but the php.ini used is not the one I edited.
Which and where is the php.ini file to edit?
Try to modify the real php.ini, you can find it running php -i | grep "php.ini" on Terminal.
Remember that sometimes you'll find only a file called php.ini.default so you have to copy the file php.ini.default in a new php.ini file using sudo cp php.ini.default php.ini
Once you create the new php.ini file you have to change the permission in order to be able to modify the content:
sudo chmod ug+w php.ini
sudo chgrp staff php.ini
Now you can open the file php.ini and modify the date.timezone line.
NOTE: Remember to remove the comment if the line is commented.
If this doesn't work try to add the init function to your AppKernel.php file (code below), this really helped me.
<?php
class AppKernel extends Kernel
{
// Other methods and variables
// Append this init function below
public function init()
{
date_default_timezone_set( 'Europe/Paris' );
parent::init();
}
}
Since this is Terminal-based run and not browser based you can easily find that out. From your Terminal, run this:
php -i | grep "php.ini"
This will output the location of php.ini used. Then edit the file via any text editor (graphic or otherwise) and set the approprite time zone.
Hope this helps.
I have a problem with the setup of Symfony 2 localy on xampp.
The installation was no problem but when I execute the check.php it says:
Your system is not ready to run Symfony2 projects
* date.timezone setting must be set
> Set the "date.timezone" setting in php.ini* (like Europe/Paris).
But the date.timezone in the php.ini is already set correctly.
you can add this to your AppKernel.php
public function init()
{
// get rid of Warning: date_default_timezone_get(): It is not safe to rely on the system's timezone
date_default_timezone_set( 'Europe/Paris' );
parent::init();
}
for some reason you have to change the date.timezone in
php.ini
in the
cli folder
got the hint when I tried to start a new project in Symfony3.
even if phpinfo() shows that the
php.ini file is in apache2 folder
If you are facing following problem :
Your system is not ready to run Symfony2 projects
* date.timezone setting must be set
> Set the "date.timezone" setting in php.ini* (like Europe/Paris)
Simply replace the |localizeddate('long','long') with |date('r') in app/Resources/views/base.html.twig file.
What worked for me is to add the -k option when restarting Apache
I have a Symfony2 project. I updated my php to 5.5.7 today and since then, I am getting the
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...
I setup the default timezone in my php.ini
[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = "Europe/Paris";
To be sure that this is the good php.ini, I was checking with
phpinfo();
And the path I ma getting there is the one I am modifying:
/usr/local/php5.5.7/lib
But in there, I see the
Default timezone UTC
Which is strange.
any idea? Thank you.
Maybe you are trying to set it in Apache's php.ini, but your CLI (Command Line Interface) php.ini is not good.
Find your php.ini file with the following command:
php -i | grep php.ini
And then search for date.timezone and set it to "Europe/Amsterdam". all valid timezone will be found here http://php.net/manual/en/timezones.php
Another way (if the other does not work), search for the file AppKernel.php, which should be under the folder app of your Symfony project directory. Overwrite the __construct function below in the class AppKernel:
<?php
class AppKernel extends Kernel
{
// Other methods and variables
// Append this init function below
public function __construct($environment, $debug)
{
date_default_timezone_set( 'Europe/Paris' );
parent::__construct($environment, $debug);
}
}
Found a similar way to fix this issue (at least it did for me).
First check where the CLI php.ini is located:
php -i | grep "php.ini"
In my case I ended up with : Configuration File (php.ini) Path => /etc
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
Now, copy the php.ini.default file named as php.ini:
sudo cp php.ini.default php.ini
In order to edit, change the permissions of the file:
sudo chmod ug+w php.ini
sudo chgrp staff php.ini
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.
Search for [Date] and make sure the following line is in the correct format:
date.timezone = "Europe/Amsterdam"
I hope this could help you out.
The current accepted answer by crack is deprecated in Symfony 2.3 and will be removed by 3.0. It should be moved to the constructor:
public function __construct($environment, $debug) {
date_default_timezone_set('Europe/Warsaw');
parent::__construct($environment, $debug);
}
Since PHP 5.5, there is a separate php.ini file for CLI interface.
If You use symfony console from command line, then this specific php.ini is used.
In Ubuntu 13.10 check file:
/etc/php5/cli/php.ini
The problem appear when we are using PHP 5.1 on Redhat or Cent OS
PHP 5.1 on RHEL/CentOS doesn't support the timezone functions
Following up on sas's answer, PHP 5.4, Symfony 2.8, I had to use
ini_set('date.timezone','<whatever timezone string>');
instead of date_default_timezone_set. I also added a call to ini_set to the top of a custom web/config.php to get that check to succeed.
add this code to Your AppKernel Class:
public function init()
{
date_default_timezone_set('Asia/Tehran');
parent::init();
}
I am constantly getting the following error :
DateTime::createFromFormat(): 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
Although I've specified the DateTime settings in my php.ini like this:
date.timezone = Asia/Jakarta
Any idea?
You're just missing some quotes.
date.timezone = "Asia/Jakarta"
Best of luck!
It could also be that you are not loading the correct php.ini file. See this post for more info: php5.3.3 date.timezone again php.ini directive not taken into account
You can use
date_default_timezone_set("Asia/Jakarta")
at the beginning of your script
Maybe this process running in php cli so, you need put this configuration inside your CLI php.ini in the following path: /etc/php5/cli/php.ini
By default the "date.timezone" was commented, so change this config:
date.timezone = Asia/Jakarta
For those who are having the same problem in Symfony 3 add the following constructor into your app/AppKernel.php file and restart nginx.
public function __construct($environment, $debug)
{
date_default_timezone_set('Asia/Jakarta');
parent::__construct($environment, $debug);
}
I also have specified the DateTime settings in my php.ini. In my case, the php.ini I edited was on
/Applications/MAMP/bin/php/php7.1.1/conf/php.ini
since I saw the path from info.php (in "Loaded Configuration File") that I generated on localhost.
Turns out it is not the one used. Try this instead:
php -i | grep php.ini
And see what the output is. Mine was:
/usr/local/etc/php/5.6
Loaded Configuration File => /usr/local/etc/php/5.6/php.ini
PHP Warning: Unknown: 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 Unknown on line 0
And then I just go to "/usr/local/etc/php/5.6" and edited the date.timezone line: removing comment (;) and added "Europe/Berlin" (or in your case "Asia/Jakarta".)
Try "php -i | grep php.ini" once again and the php warning message should be gone by now.
php -i | grep php.ini
Configuration File (php.ini) Path => /usr/local/etc/php/5.6
Loaded Configuration File => /usr/local/etc/php/5.6/php.ini
Still not working with the above solutions, try to add the following code in .htaccess of your root directory and check.
php_value date.timezone America/Denver