By Steve Suehring, Janet Valade

With the release of PHP 5.1, PHP added a setting for a default local time zone to php.ini. If you don’t set a default time zone, PHP will guess, which sometimes results in GMT. In addition, PHP displays a message advising you to set your local time zone.

To set a default time zone, follow these steps:

  1. Open php.ini in a text editor.

    Use a text editor such as Notepad, Vi, or TextEdit to open the file. The php.ini file is found in your installation directory for PHP, which is typically located beneath the /etc/ directory on Linux, in the Program Files directory on Windows, and /private/etc/ on Mac.

  2. Scroll down to the section headed [Date].


  3. Find the setting date.timezone =.

  4. If the line begins with a semicolon (;), remove the semicolon.

    The semicolon indicates a comment, or a line that’s ignored in the file. Removing the semicolon means that PHP will parse the line.

  5. Add a time zone code after the equal sign.

    Add a time zone, without quotes, to the line in order to define the time zone that the server resides within. See for a list of supported time zones and note that you don’t need to use quotation marks around the time zone when you define it in the php.ini.


  6. Restart the web server.

    PHP programs won’t use the new time zone until the web server is restarted. How you accomplish this task depends on your operating system. On Windows there is typically a widget to restart the server in the taskbar. One of the following commands typically works on Linux, depending on the variant and version of Linux:

    • Debian/Ubuntu: sudo /etc/init.d/apache2 restart

    • Red Hat/CentOS: service httpd restart

    • On Mac: sudo /usr/sbin/apachectl restart