Skip to content

How can I change the timezone using PHP/.htaccess?

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.

  1. Log in to cPanel and use the search bar in the top left to find File Manager.

  2. Click the File Manager icon. In the settings popup, select Web Root for the directory and enable Show Hidden Files (dotfiles).

  3. Once File Manager opens, locate your .htaccess file 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.

  4. Add the following line to your .htaccess file:

    php_value date.timezone "America/Chicago"

    Replace America/Chicago with the timezone identifier you need.

  5. Click Save Changes in the top right corner of the editor.

PHP supports a comprehensive list of timezone identifiers. You can find the full list in the official PHP documentation:

Supported PHP Timezones

Common examples include:

TimezoneIdentifier
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
UTCUTC
LondonEurope/London