Correct PHP time in different OS
How to correct PHP time in Ubuntu, Debian, Centos, RHEL?
Overview: This article describes how to correct PHP time in Ubuntu, Debian, CentOS, RHEL, and other Linux distributions by setting the correct timezone.
This article will help the Linux user to correct the PHP time in different OS. Follow below steps to fix the PHP time.
Step 1: Create a PHP page to show up the current time in all OS.
root@gateway:~# vim /var/www/html/time.php
<?php
$current_time = date("Y-m-d H:i:s");
echo "Current time: " . $current_time;
?>
Step 1(A): Check the current time by running the below command or by using web browser (server_ip/time.php)
root@gateway:~# php /var/www/html/time.php
Current time: 2024-04-05 06:47:58
Step 2: How to correct PHP time in Ubuntu 18, 20, 22 and Debian 10, 11, 12?
Edit the php.ini configuration file and add correct timezone.
root@gateway:~# vim /etc/php/8.2/apache2/php.ini
date.timezone = Asia/Kolkata
root@gateway:~# vim /etc/php/8.2/cli/php.ini
date.timezone = Asia/Kolkata
root@gateway:~# systemctl restart apache2
Step 2(A): How to correct PHP time in CentOS 6, 7, 8, RHEL 7, 8, 9 , RockyLinux, AlmaLinux?
root@gateway:~# vim /etc/php.ini
date.timezone = Asia/Kolkata
root@gateway:~# systemctl restart httpd
Step 3: After restarting the web service check the time again from shell and web browser.
root@gateway:~# php /var/www/html/time.php
Current time: 2024-04-05 14:18:58
Related Articles: