Howto Setup Timezone in php.ini or PHP Script on Linux Systems

undefined

Setup the default timezone is very necessary for proper data processing send from various countries. This article will help you to know how can we setup a default timezone in PHP configuration file (php.ini) or inside any php script for temporary use.

Part 1: Setup Timezone in php.ini

To setup default timezone for your php environment, follow below 4 simple steps.

1. Location of php.ini – Find out your correct php.ini configuration file. Following is some default php.ini locations

 

  • CentOS/RedHat/Fedora = /etc/php.ini
  • Ubuntu/Debian/LinuxMint = /etc/php5/apache2/php.ini

 

2. Choose correct timezone – What timezone you need to configure in your php.ini file. Use below link to find available timezones for php.

 

 

3. Update timezone in php.ini – Finally edit your php.ini configuration file and update proper timezone value in date.timezone setting tag. For example you want to configure ‘America/New_York’ as your default timezone.

 date.timezone = "Africa/Johannesburg"

4. Restart Apache Service – Now just restart Apache service as per setup.

Part 2: Setup Timezone in Single PHP Script

You can also set the timezone for a single php script by defining timezone inside the php script. Simply edit your php script and add date_default_timezone_set(“MMM”) line at top of script. Change MMM with your preferred timezone.

<?php
 date_default_timezone_set("Africa/Johannesburg");

?>

If You Appreciate What We Do Here On Mimastech, You Should Consider:

  1. Stay Connected to: Facebook | Twitter | Google+
  2. Support us via PayPal Donation
  3. Subscribe to our email newsletters.
  4. Tell other sysadmins / friends about Us - Share and Like our posts and services

We are thankful for your never ending support.

Leave a Reply

Your email address will not be published. Required fields are marked *