HostOnNet Blog

How to change the default timezone in PHP

The default timezone for PHP is defined in php.ini configuration file. So you will need to edit the file manually for changing it.

You can find the location of your php.ini file on your server/system by running below command on terminal.

php --ini

php_time_zone_1

In this example, it is found at /etc/php5/cli/php.ini

Next, find out the timezone (TZ) string of your region. For that, you can use a command-line tool called tzselect. Simply run the following command:

tzselect

php_time_zone_2

Once you have selected a continent or ocean, tzselect will print the value of TZ variable as follows. In this example, the TZ value is “Asia/Kolkata”.

php_time_zone_3

php_time_zone_4

Now open up php.ini in a text editor.

Then look up “date.timezone” variable in it.

If “date.timezone” variable definition is commented out, uncomment the line (to uncomment the line, remove the semicolon from the beginning of that line). Then change the timezone accordingly.

date.timezone = "Asia/Kolkata"

You are done!


About Vineesh Mohan

A Technical Support specialist with strong customer service and good communication skills. I live in the city of Cochin, which known as the Queen of Arabian Sea.
Posted in Linux, PHP