Introduction Many cPanel users face the issue where their hosted PHP scripts use a different time zone than the server’s default time. Additionally, cron jobs executed via cPanel follow the server time instead of the user’s preferred time zone. This can cause confusion and affect scheduling tasks such as automated backups, scheduled emails, or time-sensitive scripts.
If your server is located in the USA (e.g., Pacific Standard Time – PST), but your business operates in Bangladesh (Asia/Dhaka time zone), you might need to set a different time zone for your cPanel account.
In this guide, we will show you how to:
- Change the time zone for a cPanel user
- Ensure cron jobs use the correct time zone
- Verify that the changes are applied correctly
Step 1: Set the Time Zone for PHP Scripts
Method 1: Use
If your website is running PHP, the easiest way to set the correct time zone is by modifying the .htaccess
file inside your public_html
directory.
Steps:
- Log in to cPanel.
- Open File Manager.
- Navigate to
public_html/
. - Edit or create a
.htaccess
file. - Add the following line:
php_value date.timezone "Asia/Dhaka"
- Save the file and refresh your website.
To verify that the change is working, create a timezone.php
file inside public_html
and add this code:
<?php
echo "Current Timezone: " . date_default_timezone_get() . "<br>";
echo "Current Time: " . date('Y-m-d H:i:s');
?>
Visit https://yourdomain.com/timezone.php
and check if it displays the correct time.
Method 2: Use
If .htaccess
does not work, you can try setting the time zone inside the php.ini
file.
Steps:
- In cPanel, go to File Manager.
- Inside
public_html/
, create or editphp.ini
. - Add the following line:
date.timezone = "Asia/Dhaka"
- Save and test using
timezone.php
as shown above.
Step 2: Change Time Zone for Cron Jobs
By default, cron jobs in cPanel use the server’s time zone. To override this, add the “** variable** before running any cron job.
Steps:
- Log in to cPanel.
- Go to Cron Jobs.
- When adding a cron job, modify the command like this:
TZ="Asia/Dhaka" php -q /home/your_cpanel_user/public_html/script.php
- Save the cron job.
✅ This ensures that the cron job runs in the correct time zone.
To verify, create a test cron job:
* * * * * TZ="Asia/Dhaka" date >> /home/your_cpanel_user/public_html/cron_log.txt
After a minute, check cron_log.txt
to see if the time matches Asia/Dhaka.
Step 3: Set Time Zone for Terminal (SSH) & System Commands
If your cPanel account has Terminal (SSH) access, you can permanently change the time zone for your user.
Method 1: Temporary Change for Current Session
To set the time zone only for the current session, run:
export TZ="Asia/Dhaka"
To verify, run:
date
This change will reset after logout.
Method 2: Permanent Change for the User
- Open Terminal from cPanel.
- Edit the
.bashrc
file:nano ~/.bashrc
- Add this line at the bottom:
export TZ="Asia/Dhaka"
- Save the file (
CTRL + X
, thenY
, thenENTER
). - Apply the changes:
source ~/.bashrc
- Verify:
date
✅ Now, every time this user logs in, the time zone will automatically be set.
---
Final Verification & Testing
To ensure everything is working:
1. Check PHP time zone: Run `timezone.php`.
2. Verify cron jobs: Check `cron_log.txt` for correct timestamps.
3. Confirm SSH timezone: Run `date` in Terminal.
4. Check cron environment: Run:
env | grep TZ
✅ If it shows TZ=Asia/Dhaka
, everything is configured correctly!
Conclusion
By following these steps, you can ensure that your PHP scripts, cron jobs, and SSH commands all use the correct time zone for your specific cPanel user, without affecting the entire WHM server.
If you’re managing multiple cPanel accounts on a WHM server, this method allows each user to have their own preferred time zone without requiring root access.