Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't set default timezone in PHP

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.

like image 896
Stann Avatar asked May 27 '11 19:05

Stann


People also ask

What is the default timezone in php?

UTC is the default after 5.4. 0.

Which of the following is the php ini setting that controls the default time zone?

The date_default_timezone_set() function sets the default timezone used by all date/time functions in the script.

How do I find my default timezone?

The getDefault() method of TimeZone class in Java is used to know the default TimeZone for this system or host. This may vary in according to the implementation in different environment. Parameters: The method does not take any parameters. Return Value: The method returns the default TimeZone of the host.


4 Answers

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.

like image 120
Andrew Zhilin Avatar answered Oct 01 '22 21:10

Andrew Zhilin


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
like image 42
thiru Avatar answered Oct 01 '22 22:10

thiru


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).

like image 22
KingCrunch Avatar answered Oct 01 '22 21:10

KingCrunch


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

like image 33
Dave Kiss Avatar answered Oct 01 '22 22:10

Dave Kiss