How to Set the Correct PHP Timezone on Your cPanel/WHM Server

Setting the correct timezone for PHP is essential to ensure accurate timestamps, logging, and date handling on your server. Follow these simple steps to set the PHP timezone on your cPanel/WHM server.

Steps to Change the PHP Timezone:

1. Access the Server via SSH

Log into your server using SSH:

ssh root@your-server-ip

2. Edit the php.ini File

For PHP 8.2, open the configuration file:

nano /opt/cpanel/ea-php82/root/etc/php.ini

3. Set the date.timezone Directive

Search for date.timezone in the file (press Ctrl + W in nano). Set the timezone to the desired region. For example:

date.timezone = "America/New_York"

Replace "America/New_York" with the appropriate timezone string (e.g., Europe/London, Asia/Tokyo).

4. Save and Exit

After editing, save and exit the file:

  • Press Ctrl + X, then Y to confirm, and press Enter.

5. Restart PHP or Apache

Restart PHP-FPM (if using PHP-FPM):

service php-fpm restart

Or restart Apache (if using mod_php):

service httpd restart

6. Verify the Change

To verify the timezone, create a simple PHP file:

<?php
echo date_default_timezone_get();
?>

Visit the file in a browser, and it should display the configured timezone (e.g., America/New_York).