How to set the default timezone in PHP
Question: How can I set the default timezone used by all date/time related PHP functions?
The default timezone for PHP is defined in php.ini configuration file. So you will need to edit the file by hand.
First, find the location of php.ini on your system as follows. In this example, it is found at /etc/php5/cli/php.ini.
$ php --ini
Configuration File (php.ini) Path: /etc/php5/cli
Loaded Configuration File: /etc/php5/cli/php.ini
Scan for additional .ini files in: /etc/php5/cli/conf.d
Additional .ini files parsed: /etc/php5/cli/conf.d/10-pdo.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
You will then go through interactive menu to identify your region.
After you are done, tzselect will print the value of TZ variable as follows. In this example, the TZ value is "America/New York".
Now open up php.ini in a text editor, and look up "date.timezone" variable in it. If "date.timezone" variable definition is commented out, uncomment the line. Then change the timezone accordingly. You are done!
date.timezone = "America/New_York"