Cannot Set date.timezone In php.ini file

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:


so I changed the date.timezone setting into this:

; Defines the default timezone used by the date functions
date.timezone = Asia/Jakarta

;date.default_latitude = 31.7667

;date.default_longitude = 35.2333

;date.sunrise_zenith = 90.583333

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

Here is Solutions:

We have many solutions to this problem, But we recommend you to use the first solution because it is tested & true solution that will 100% work for you.

Solution 1

Try this:

date.timezone = "Asia/Jakarta"


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


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


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

Solution 2

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


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:


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 !!!

Solution 3

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

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


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

It works for me now.

Solution 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


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

Solution 5

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

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

; Defines the default timezone used by the date functions
; 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 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.

Solution 6

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.

Solution 7

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.

Solution 8

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"

Solution 9

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

Solution 10

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


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

Solution 11

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.

Solution 12

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

Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply