Solusi “date.timezone” Error pada PHP: date(), It is not safe to rely on the system’s timezone settings

saya baru saja install php-fpm dan menjalankan phpMyAdmin dan files php ternyata muncul error warning timezone. Seperti nampak di bawah ini:

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 'America/New_York' for 'EST/-5.0/no DST'  instead in /home/rahmatriyanto/www/localhost/tes.php on line 6

Setelah saya cek di berbagai referensi ternyata error ini disebabkan timezone belum disetting.
Untuk mengatasi masalah ini bisa dilakukan dengan menambakan
date.timezone = GMT di bawah [Date] pada file /etc/php.ini

Langkahnya seperti dibawah ini:

  1. login terminal sebagai root
  2. nano /etc/php.ini carai baris [Date]
    [Date] ; Defines the default timezone used by the date functions ; https://www.php.net/manual/en/datetime.configuration.php#ini.date.timezone ;date.timezone = ; https://www.php.net/manual/en/datetime.configuration.php#ini.date.default-latitude ;date.default_latitude = 31.7667 ; https://www.php.net/manual/en/datetime.configuration.php#ini.date.default-longitude ;date.default_longitude = 35.2333 ; https://www.php.net/manual/en/datetime.configuration.php#ini.date.sunrise-zenith ;date.sunrise_zenith = 90.583333 ; https://www.php.net/manual/en/datetime.configuration.php#ini.date.sunset-zenith ;date.sunset_zenith = 90.583333

    Tambahkan date.timezone = GMT

  3. service php-fpm restart

Semoga bermanfaat

Leave a Reply

Your email address will not be published. Required fields are marked *