How to Set the Timezone in cPanel Using .htaccess
Overview
By default, PHP on a shared cPanel server usually runs on UTC. If your website shows the wrong date/time (e.g. timestamps, order times, blog post dates), you need to set the PHP timezone for your account. The easiest way to do this without touching PHP code is through the .htaccess file.
Method 1: Set Timezone via .htaccess (Recommended for Shared Hosting)
- Log in to cPanel.
- Open File Manager.
- Navigate to
public_html(or the folder for the specific domain/subdomain). - Locate the
.htaccessfile.- If it's not visible, click Settings (top right) and enable Show Hidden Files (dotfiles).
- Right-click
.htaccess→ Edit (or Code Editor). - Add this line:
php_value date.timezone "Asia/Colombo"
- Save the file.
- Refresh your site and check if the time is correct.
Replace
Asia/Colombowith your required PHP timezone identifier.