change default timezone in Apache

How to Change Default Timezone in Apache/PHP

The default timezone for Apache/PHP is UTC (Coordinated Universal Time). Sometimes you may need to change Apache/PHP time zone to sync it with other systems or because your customers are located in a different timezone. In this article, we will look at how to change default timezone in Apache/PHP. You can use these steps to set Apache/PHP timezone as per your requirement.


Change Default Timezone in Apache/PHP

Here is how to set Apache/PHP timezone. We will look at two ways to set default timezone – using .htaccess in Apache and using php.ini file in PHP.


Change default timezone using .htaccess file

In case you don’t use Apache with PHP, or you don’t have access to php.ini, you can set default time in Apache web server using .htaccess file. Before proceeding further, please make sure that you have enabled mod_rewrite (.htaccess) on your Apache web server.

Open .htaccess file, typically located at /var/www/html/.htaccess

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

Add the following line to set environment variable TZ (for timezone) in Apache web server to Eastern Time zone in US.

SetEnv TZ America/New_York

Save and close the file.

Also read : How to Set Up Apache Virtual Hosts in Apache

In the above line, we specify SetEnv TZ to set timezone environment variable in Apache, followed by ‘America/New York’ to specify Eastern Time. Here is a list of all available timezones in Apache/PHP.

Restart Apache Server to apply changes.

$ sudo service apache2 restart

Also read : How to Install mod_security in CentOS 7


Change default timezone using php.ini

If you don’t have access to .htaccess file or if you use PHP with Apache, then here is how to set default timezone in Apache/PHP.

Open php.ini, typically at /etc/php.ini

$ sudo vi /etc/php.ini

Uncomment/Add the following lines to set default timezone in PHP.

;[Date] 
;date.timezone = UTC

Change them to the following, to set default time to Eastern timezone.

[Date] 
date.timezone = America/New_York

Also read : How to Create Custom 404 Page in Apache

Restart Apache Server to apply changes.

$ sudo service apache2 restart

That’s it. Now your default timezone in Apache will be changed. Ubiq makes it easy to visualize data in minutes, and monitor in real-time dashboards. Try it Today!

mm

About Ubiq

Ubiq is a powerful dashboard & reporting platform for small & medium businesses. Build dashboards, charts & reports for your business in minutes. Get insights from data quickly. Try it for free today!