How can I change the timezone using PHP/.htaccess?
Overview
Section titled “Overview”If you need to localize the time displayed by your PHP applications, scripts, or website, you can set a custom timezone through your .htaccess file. The server’s system timezone itself cannot be changed, but the PHP timezone used by your applications can be overridden on a per-account basis.
For this guide we will use cPanel’s File Manager, though the same changes can be made via SSH or any FTP/SFTP client.
Changing the Timezone via .htaccess
Section titled “Changing the Timezone via .htaccess”-
Log in to cPanel and use the search bar in the top left to find File Manager.
-
Click the File Manager icon. In the settings popup, select Web Root for the directory and enable Show Hidden Files (dotfiles).
-
Once File Manager opens, locate your
.htaccessfile in your site’s document root and click on it. With the file highlighted, select Edit from the top navigation bar. When prompted with a confirmation dialog, click Edit again to open the editor. -
Add the following line to your
.htaccessfile:php_value date.timezone "America/Chicago"Replace
America/Chicagowith the timezone identifier you need. -
Click Save Changes in the top right corner of the editor.
Finding Your Timezone Identifier
Section titled “Finding Your Timezone Identifier”PHP supports a comprehensive list of timezone identifiers. You can find the full list in the official PHP documentation:
Common examples include:
| Timezone | Identifier |
|---|---|
| Eastern Time (US) | America/New_York |
| Central Time (US) | America/Chicago |
| Mountain Time (US) | America/Denver |
| Pacific Time (US) | America/Los_Angeles |
| Eastern Time (Canada) | America/Toronto |
| UTC | UTC |
| London | Europe/London |