php date.timezone not working correctly for command line script only

php

Solution

CLI and webserver (and cgi and fpm) use different `php.ini`-files. Because you say you see the right value in you browser I guess you edited the wrong one. On cli type

php --ini

To find out, which is the one you must edit. It's the one in the second line, for example

Loaded Configuration File:         /etc/php5/cli/php.ini

Problem

I have this entry in my php.ini file: ``` date.timezone = 'Europe/London'; ``` But every time i use the DateTime() in a command line script i still get the following 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/London' for 'BST/1.0/DST' instead ``` I therefore have to do the following in any scripts to get this to work: ``` date_default_timezone_set('Europe/London'); ``` What else can be causing this error? UPDATE I used the following in both command line and web browser: ``` <?php var_dump(ini_get('date.timezone')); exit; ``` In command line i get: ``` string(0) "" ``` In web browser i get: ``` string(13) "Europe/London" ```

Original source