How to Change Default Time Zone in .htaccess


change default time zone apache

By default, Apache will use the system time zone of the server where it is installed. However, if you want to change it to something else, then you can do that easily using .htaccess file. Here’s how to change default time zone in .htaccess file in Apache web server.

 

How to Change Default Time Zone in .htaccess

Here are the steps to change default time zone in .htaccess.

 

By default, Apache’s default time zone is based on the physical location of the server. For example, if it is located on California, then most likely, its time zone will be set to Pacific Time. However, sometimes, your website may be catering to audience in a different timezone.

Sure, you can change the time zone using php.ini but that won’t include the .html and log files. That is where .htaccess file comes in handy.

It allows you to change Apache server configuration without accessing its config files.

 

1. Enable .htaccess

Before you proceed, please ensure you have enabled .htaccess file for Apache. Here’s how to do it:

Place your .htaccess file in the root document folder of your website (/var/www/html) and add the following rules, depending on your use case.

 

2. Update .htaccess file

Open .htaccess file using a text editor


$sudo vim /var/www/html/.htaccess

 

Add the following SetEnv directive to set Apache’s time zone. Here’s the syntax,


SetEnv TZ timezone

timezone – time zone you want to set

For example, if you want to set it to Eastern Standard Time,


SetEnv TZ America/Washington

 

Here’s a list of supported time zone codes for Apache, for different parts of the world.

 

3. Restart Apache Web Server

Restart Apache web server to apply changes.


$ sudo service apache2 restart

 

 

 

About Sreeram Sreenivasan

Sreeram Sreenivasan is the Founder of Ubiq, a business dashboard & reporting platform for small & medium businesses. Ubiq makes it easy to build business dashboards & reports for your business. Try it for free today!