HOWTO: Set Default Timezone in PHP

Setting your default timezone in PHP is a very easy task and may be needed for some applications.  If you fall into this bucket, all you need to do is….

  1. Open up your default php.ini file (or the one you wish to edit).  I can help you find your default php.ini file, if you don’t know where it is.
  2. Find the line that says ;date.timezone
  3. Uncomment that line by removing the semi-colon, then set it equal to the appropriate timezone.  For instance:
    • date.timezone = America/New_York
  4. Save the file and restart Apache

In case you’re wondering… I write these how to’s to help me remember.  Might not be so helpful for everyone else, but maybe.

HOW TO find php.ini in Ubuntu

Looking for the primary php.ini in Ubuntu to change some default settings across Apache?  No problemo.  Here are three different options for finding it:

  • Try running this <?php phpinfo(); ?> through your PHP interpreter.  This will show you where your main php.ini file is.
  • Or you can try searching for it in the shell:  find / -name php.ini
  • If all else fails, give it the old college try, and see if my setting works for you:  /etc/php5/apache2/php.ini (I’m on Ubuntu 9.10 – karmic).

This should just about do it for you, old chap.