Php date.timezone does not work correctly only for command line script

I have this entry in php.ini file:

date.timezone = 'Europe/London'; 

But every time I use DateTime () in a command line script, I still get the following error:

 Exception: DateTime::__construct(): It is not safe to rely on the system 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/London' for 'BST/1.0/DST' instead 

So I have to do the following in any scripts to get this to work:

 date_default_timezone_set('Europe/London'); 

What else could cause this error?

UPDATE

On the command line and in a web browser, I used the following:

 <?php var_dump(ini_get('date.timezone')); exit; 

At the command prompt, I get:

 string(0) "" 

In a web browser, I get:

 string(13) "Europe/London" 
+8
php
source share
2 answers

The CLI and webserver (and cgi and fpm) use different php.ini files. Since you say that you see the correct value in your browser, I think you edited the wrong one. Cli type

 php --ini 

To find out what you need to change. This is the second in the second line, for example

 Loaded Configuration File: /etc/php5/cli/php.ini 
+17
source share

Some servers (such as a media temple) perform configurations for specific domains. Thus, the server will access the shared php.ini file located under /etc/php.ini, but the browser will gain access to the php.ini domain file. There may be a problem.

+1
source share

All Articles