12

I've set this in my php.ini file, and restarted php5-fpm process

date.timezone = "UTC"

But phpinfo() script still shows this:

date.timezone   America/New_York    America/New_York

phpinfo() also shows that correct ini file is being used.

I've restarted - but problem persisted. Then I did:

sudo service nginx stop
sudo service apache2 start

and date.timezone is correct when mod-php (apache2) is in use instead of fcgi that is php in nginx.

random
  • 9,774
  • 10
  • 66
  • 83
Stann
  • 13,518
  • 19
  • 65
  • 73
  • 1
    Make sure you updated the correct php.ini... ofttimes there's more than one on a server. You can find the correct one using phpinfo() – Mark Baker May 27 '11 at 19:38
  • um. yes. - I did check that correct file is used prior to asking. - it's in my question actually. – Stann May 27 '11 at 19:44
  • I had a very similar problem, except with EasyPHP - so for future Googlers, the problem is in `[easyphp]/conf_files/httpd.conf` on line 1022. – nkorth Jun 18 '11 at 19:50
  • Thanks for the pool.d value. I couldn't remember the syntax, fixed me right up. – Jim Oct 09 '11 at 05:18
  • 1
    Is it possible that the script itself is overriding the php.ini value for the timezone? – Amy Anuszewski May 27 '11 at 19:55
  • I'm testing from cli also. file only contains this: echo PHP_EOL . 'timezone: ' . date_default_timezone_get(); – Stann May 27 '11 at 19:59
  • never mind. it works in cli mode. It still however doesn't work in fpm mode. – Stann May 27 '11 at 20:07
  • 1
    @Stann - This question is kinda old and you may have figured it out alright. But if you haven't, you needed to restart the php-fpm pool. I had to run `/etc/init.d/php-fpm-5.5 restart` to get this to work on a CentOS system. Restarting nginx alone wouldn't help. – Chandranshu Jan 21 '14 at 12:28

5 Answers5

7

You probably edited the wrong php.ini. See php_info() (or php -i for the cli interpreter) which one is used. For example on ubuntu (and probably other linux distributions) its /etc/php5/cli/php.ini for the cli-interpreter, /etc/php5/apache/php.ini/ for the one used by Apaches mod_php and /etc/php5/cgi/php.ini used by php5-cgi (which is used by nginx).

KingCrunch
  • 128,817
  • 21
  • 151
  • 173
  • Yep. I thought of that. So I actually change date.timezone in all php.ini config files: cli, apache2, cgi, fpm. It does work correctly with cli and apache2. it doesn't in fpm. – Stann May 27 '11 at 20:06
2

The problem seems to be be with php-fpm processes that lingers around and refers to the old php.ini file settings. This worked for me:

Get the process ids for php-fpm

root@thiru:/etc/php5/fpm/conf.d# ps aux | head -1 && ps aux | grep php-fpm | grep -v grep
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root     32650  0.0  0.5  86624 17032 ?        Ss   21:44   0:00    php-fpm: master process (/etc/php5/fpm/php-fpm.conf)                    
www-data 32652  0.0  0.1  86624  4700 ?        S    21:44   0:00 php-fpm: pool www                                                       
www-data 32653  0.0  0.1  86624  4704 ?        S    21:44   0:00 php-fpm: pool www   

Kill the processes. Starting with the master.

kill -9 32650
kill -9 32652
kill -9 32653

Start php-fpm using the init script

service php5-fpm start or /etc/init.d/php5-fpm start
thiru
  • 96
  • 1
  • 4
2

List of supported timezone values: http://php.net/timezones

KingCrunch
  • 128,817
  • 21
  • 151
  • 173
Dave Kiss
  • 10,289
  • 11
  • 53
  • 75
1

In my installation BY DEFAULT I had realy weird configuration. File /etc/php/7.3/fpm/pool.d/www.conf had such a setting at the end of the file

php_admin_value[date.timezone] = UTC

It lead to timezone setting being ignored in php.ini and default system timezone being ignored.

Andrew Zhilin
  • 1,654
  • 16
  • 11
0

Check your FPM Installation, if you have a pool with a active chroot!

If you have a chroot environment, you need to copy the file /etc/localtime (symlink to /usr/share/zoneinfo/xyz) and the directory /usr/share/zoneinfo to your chroot.

Possible Error-Messages:

Fatal error: phpinfo(): Timezone database is corrupt - this should *never* happen!  
Warning: phpinfo(): Invalid date.timezone value ‘UTC’, we selected the timezone ‘UTC’ for now.

See https://serverfault.com/questions/413293/php-fpm-chroot-jail-corrupts-timezone-db

Octeny
  • 499
  • 5
  • 7