Timezone with symfony 2
I've got some troubles whith Symfony 2, trying to generate schema via :
php console/app generate:schema:create
I've got a pretty error :
[Exception]
DateTime::__construct(): 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 'Europe/Berlin' for 'CEST/2.0/DST' instead
Thus, I'm trying to change the timezone in my php.ini with
date.timezone = 'Europe/Paris'
but even if I'm reloading my apache, I still get
date.timezone Europe/Zurich Europe/Zurich
if I look at my phpinfo()
, so I don't really know what should I try next ... And I'm not even sure that I'm in the good 开发者_开发技巧way.
Thanks for helping me
On mac, if you have /etc/php.ini.default
, do
sudo cp /etc/php.ini.default /etc/php.ini
and then do
php --ini
to see that it now loads a php.ini file.
this that trick
and se /etc/php5/cli/php.ini
and /etc/php5/apache2/php.ini
datetime = 'America/Lima'
for example
and run command
$ sudo apt-get install php5-sqlite
$ sudo /etc/init.d/apache2 restart
Some third-party distributions of PHP (including MAMP) have hard-coded the timezone. For instance, MAMP 2.0 is hard-coded to Europe/Berlin, and there is no way to change this. Even changing the value in the php.ini template has no effect, because MAMP overwrites your value. Are you using PHP from source, a pre-compiled package, or PHP as a part of some kind of LAMP stack?
If you are on debian based, you must modify the parameter in the file /etc/php5/cli/php.ini, changing it in /etc/php5/apache2/php.ini has no effect.
I know this is an old ticket, but since I was having a problem with this too, and it's still open I thought I'd share my quick 'n' dirty solution:
In my case, date.default
was not set at all and I wasn't in a position to change php.ini
. So, as a stopgap I added date_default_timezone_set('Europe/Dublin')
at the start of web/app.php
to change the timezone at runtime, which worked nicely for me.
If you're using the console to run any commands you will probably have to add the call to the the top of this script also.
I ran into this problem with my shared host. they told me I couldn't change time zones via php.ini, but you can try an .htaccess
file instead.
create the .htaccess
in the folder where Symfony is installed and put the following code in it:
SetEnv TZ America/Sao_Paulo
hope this helps.
cheers, Luciano
For Windows, I installed XAMPP for the webserver and downloaded PHP and installed it so that I could run the symfony commands from command prompt.
In this case, the php.ini
file used when I execute a Symfony command is located in C:\Program Files(x86)\PHP\php.ini
. You have to have admin rights in order to edit this file, so I launched Notepad++ as administrator and opened the file.
Look for date.timezone
and modify it according to your timezone e.g. date.timezone = Africa/Nairobi
. Timezones are listed on the php website, just search php, timezones
. No need to restart your computer or webserver.
I just encountered this problem with XAMPP on Mac 10.11.5, PHP 5.6.8
My error read "Warning: date_default_timezone_get(): Invalid date.timezone value 'America/Los Angeles',"
I fixed it by finding the only problem was the missing underscore in the "Los Angeles" entry for my PHP.ini date.timezone setting.
Try to execute this command:
sudo ln -s /usr/local/php5/lib/php.ini /etc/php.ini
Mac in my case. First - config path, second - don't change.
精彩评论