Ubuntu: How to set PHP’s default Time Zone CodeUnit 21 FEB 2011

From PHP 5.1 onwards, you have been able to define the default time zone which is to be used in PHP regardless of what time zone the server or Apache might be using. To do this requires some minor adjustments to your php.ini config file.

First, access your php.ini file with:

sudo nano /etc/php5/apache2/php.ini

Locate the Module Settings section, specifically [Date] in the php.ini file (Mine was around line 945). You will see a “;date.timezone = ” entry. Uncomment the line by removing the ; and then add to it the timezone you wish to use. I wanted to set for GMT, so my uncommented line looks like this:

date.timezone = Etc/GMT

You can find a list of available time zones here: http://www.php.net/manual/en/timezones.php

Save your changes and reload apache (I like doing this just to be sure):

sudo service apache2 restart


Related Posts:

About Craig Lotter

South African software architect and developer at Touchwork. Husband to a cupcake baker and father to two little girls. I don't have time for myself any more.