PHP Fix date & time issue in Ubuntu Apache/nginx server

Go to the php.ini file and fix date.timezone region

sudo vim /etc/php/8.2/fpm/php.ini
or,
sudo vim /etc/php/8.2/apache2/php.ini

date.timezone = "Asia/Kolkata"

Restart/Reload apache/nginx service once configuration change
sudo service nginx restart
sudo service apache2 restart

 Create a php test file on document root to check date & time on web

vi /var/www/html/phpinfo.php

<?php

echo date("d-m-y h:i:s",time());

$timezone = date_default_timezone_get();

echo "The current server timezone is: " . $timezone;?>

Open web browser and check status
https://uttarpradeshtimes.com/phpinfo.php
Output: 
25-12-23 12:26:45The current server timezone is: Asia/Kolkata


Fix server date & time in Ubuntu server Linux Server

Get/Copy your time zone from command

  timedatectl list-timezones

Run command and set you timezone

 sudo timedatectl set-timezone Asia/Kolkata

Run command to check date
date
Output:
Mon Dec 25 12:37:13 IST 2023

Share on Google Plus

About Penguin Technology

I am a passionate cloud and DevOps professional specializing in Linux and open-source solutions. Through this blog, I share my knowledge and experience with the community, offering tips and insights on cloud technologies and DevOps practices.
    Blogger Comment

0 comments:

Post a Comment