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:
[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..
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.
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).
<?php phpinfo(); ?>
What’s the .ini in the output? Still the same?
After the php.ini edit, just restart the webserver (apache or nginx) …
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 !!!
You should check out by locate php.in, if there somewhere has another one.
for me. there should have CLI for command line interface:
It works for me now.
Another solution for me after compiling PHP from source was to check php.ini was actually loading a config file. From command line
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 -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 start) and it works fine. For some reason it got copied wrong.
- Distro: Centos 7
- Web Server: Nginx
- Type: EC2 Instance
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] 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.
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.
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.
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>
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
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.
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.
Iam using PHP 7.3.6.
- open xampp/php/php.ini
- go to line 1967
- set line
- Restart Apache
Hope answer your question
Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂