22

I'm using php5.5 and getting this error whenever I used the date function in PHP:

 Warning: phpinfo(): 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 the timezone 'UTC' for now, but please set date.timezone to select your timezone. in /var/www/info.php on line 1

the loaded configuration file is here:

/etc/php5/apache2/php.ini 

so I changed the date.timezone setting into this:

[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = Asia/Jakarta

; http://php.net/date.default-latitude
;date.default_latitude = 31.7667

; http://php.net/date.default-longitude
;date.default_longitude = 35.2333

; http://php.net/date.sunrise-zenith
;date.sunrise_zenith = 90.583333

; http://php.net/date.sunset-zenith
;date.sunset_zenith = 90.583333

Then I restart the server:

sudo /etc/init.d/apache2 restart

but still getting this error, I tried to check the .ini file in the Additional ini file location but none of it is overriding the date.timezone setting

I've checked the php.ini file permission, but still not working please guide me to solve this problem, thanks..

3
  • 1
    Note: the php-cli's php.ini file is different then apache2's php.ini file. I suggest symbolic linking one to another to keep them in sync and avoid confusion! Feb 15, 2014 at 19:43
  • would this be on debian?
    – Jure Špik
    Dec 24, 2014 at 10:32
  • Check for the conflicting settings in you php.ini, I had same and in my case xdebug settings defined before date.timezone causing this thing: For more detail refer: stackoverflow.com/questions/36128558/…
    – mukund
    Mar 21, 2016 at 11:59

12 Answers 12

19

Try this:

date.timezone = "Asia/Jakarta"

Edit:

Let's locate the correct php.ini. Fire this within apache / nginx / whatever web server deamon your using (because the command line version may be different by the one used by it).

<?php
phpinfo();
?>

What's the .ini in the output? Still the same?

Edit2:

After the php.ini edit, just restart the webserver (apache or nginx) ...

8
  • are you sure that's the php.ini your using? Dec 8, 2013 at 9:19
  • yes , I'm very sure, I changed the php.ini located in the loaded configuration file
    – Edxz
    Dec 8, 2013 at 9:22
  • are you sure you did not overwrite the date.timezone within the same file? Dec 8, 2013 at 9:22
  • Yes, I've searched for another occurences of date.timezone but found none
    – Edxz
    Dec 8, 2013 at 9:24
  • can you temporarily solve it using date_default_timezone_set("Asia/Jakarta"); ? Dec 8, 2013 at 9:31
16

finally solved my problem, this is my Loaded Configuration File:

/etc/php5/apache2/php.ini 

modified the date.timezone here but it's not working.

So, I check the "Scan this dir for additional .ini files " values in phpinfo() which point to:

/etc/php5/apache2/conf.d 

then I search date.timezone from all files in that folder but found none.

this is my Additional .ini file parsed value in phpinfo():

/etc/php5/apache2/conf.d/05-opcache.ini, /etc/php5/apache2/conf.d/10-pdo.ini, /etc/php5/apache2/conf.d/20-json.ini, /etc/php5/apache2/conf.d/20-mysql.ini, /etc/php5/apache2/conf.d/20-mysqli.ini, /etc/php5/apache2/conf.d/20-pdo_mysql.ini, /etc/php5/apache2/conf.d/20-xdebug.ini, /etc/php5/apache2/conf.d/30-mcrypt.ini 

I modified /etc/php5/apache2/conf.d/20-xdebug.ini, and appended this line:

date.timezone = Asia/Jakarta

very weird but this solved my problem !!!

2
  • It might be related to: forums.cpanel.net/f5/…
    – Meetai.com
    Feb 21, 2014 at 3:32
  • 1
    I also wanted to add that I found an .ini file in my "additional .ini files" directory called 99-liip-developer.ini, not sure how it got there but it had date.timezone = Europe/Zurich and was driving me nuts, deleted and my code in the php.ini file worked properly
    – doz87
    Aug 10, 2016 at 10:17
7

You should check out by locate php.in, if there somewhere has another one.

for me. there should have CLI for command line interface:

/etc/php5/cli/php.ini
/etc/php5/fpm/php.ini

change the /etc/php5/cli/php.ini

It works for me now.

4

Another solution for me after compiling PHP from source was to check php.ini was actually loading a config file. From command line

php --ini

returns

Configuration File (php.ini) Path: /usr/local/lib
Loaded Configuration File:         (none)
Scan for additional .ini files in: (none)
Additional .ini files parsed:      (none)

Find it.

find -name "php.ini" #it was in /usr/local/php/php.ini
cp /usr/local/php/php.ini /usr/local/lib/php.ini

Restart php (in my case, /etc/init.d/php-fpm stop, /etc/init.d/php-fpm start) and it works fine. For some reason it got copied wrong.

  • Distro: Centos 7
  • Web Server: Nginx
  • Type: EC2 Instance
1
  • (on macOS Sierra here): Note that in my installation, php -i | grep php.ini was telling me that my php.ini was /etc/php.ini. Yet, when i ran php --ini, I was able to see that my php.ini was actually loading from /usr/local/etc/php/5.6/php.ini. I don't know why php cli shows 2 values, but in case this helps someone. Apr 19, 2017 at 1:54
3

In my case I had 2 date.timezone= records in the php.ini file and the last one was overriding the first one. removing one of them solved my problem.

Also don't forget you need to restart the web server process.

2

I've faced the same issue recently with PHP 5.6.4.

  • PHP 5.6.4 behaves strange
  • PHP 5.6.11 behaves normally as expected

When I put the date.timezone configuration option under [PHP] section in the configuration file it works fine for PHP 5.6.4. For example I've added the option at the very beginning of the php.ini file

[PHP]
date.timezone = "Europe/Stockholm"

But when I put the configuration option how this is shown in the example under [Date] section it does not work as expected, it looks like the option is ignored

[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
; this does not work for me for PHP 5.6.4 but works fine for PHP 5.6.11
date.timezone = "Europe/Stockholm"

When I add option to the 20-xdebug.ini like it is suggestion in the accepted answer https://stackoverflow.com/a/20731466/2111430 the option is accepted because this file has only [PHP] section. Out of curiosity I tried other included ini files and it looks like I can use any one.

One more time, the issue happened for me only with PHP 5.6.4. When I changed the option on the server with PHP 5.6.11 it behaved exactly like I expected.

1

It worked for me when I noticed that the date.timezone entry in php.ini was commented out. After removing the semicolon the timezone was set correctly.

1

If you set the date.timezone value in php.ini but it does not work (ie. local value and master value are different) then you might need to update something like this in your apache configuration file:

<IfModule mod_php5.c>
  php_value date.timezone "Europe/Paris"
</IfModule>

1

Check for the conflicting settings in you php.ini, I had same issue and in my case xdebug settings defined before date.timezone causing this thing: For more detail refer: PHP Xdebug issue - date.timezone & session.save_path undefined

0

some command line php application installer (like the symfony installer, or even when php scripts are run from cli), use the ini file inside the php-cli directory

/etc/php5/cli/php.ini


this solved my similar issue in dependency checking process while installing Symfony.

0

I fixed this in Mac OSX El Captain creating a folder structure: /Library/Server/Web/Config/php and then creating a php.ini inside this new php folder just with the date.timezone directive.

0

Iam using PHP 7.3.6.

  1. open xampp/php/php.ini
  2. go to line 1967
  3. set line date.timezone=Asia/Jakarta
  4. Restart Apache

enter image description here

Hope answer your question

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.