• Home
  • Ubuntu 20.04
    • Upgrade Ubuntu
    • Install Java
    • Install Node.js
    • Install Docker
    • Install LAMP Stack
  • Tutorials
    • AWS
    • Shell Scripting
    • Docker
    • Git
    • MongoDB
  • Funny Tools
  • FeedBack
  • Submit Article
  • About Us
TecAdmin
Menu
  • Home
  • Ubuntu 20.04
    • Upgrade Ubuntu
    • Install Java
    • Install Node.js
    • Install Docker
    • Install LAMP Stack
  • Tutorials
    • AWS
    • Shell Scripting
    • Docker
    • Git
    • MongoDB
  • Funny Tools
  • FeedBack
  • Submit Article
  • About Us

How to Setup Timezone in php.ini or PHP Script

Written by Rahul, Updated on June 5, 2019

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

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/php/VERSION/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.

  • http://php.net/manual/en/timezones.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 = "America/New_York"
    

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

    Setup Timezone in 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(“XXX”) line at top of script. Change XXX with your preferred timezone.

    1
    2
    3
    <?php
       date_default_timezone_set("America/New_York");
    ?>

    Share it!
    Share on Facebook
    Share on Twitter
    Share on LinkedIn
    Share on Reddit
    Share on Tumblr
    Share on Whatsapp
    Rahul
    Rahul
    Connect on Facebook Connect on Twitter

    I, Rahul Kumar am the founder and chief editor of TecAdmin.net. I am a Red Hat Certified Engineer (RHCE) and working as an IT professional since 2009..

    Leave a Reply Cancel reply

    Popular Posts

    • How To Install Python 3.9 on Debian 10
    • Download Ubuntu 20.04 LTS – DVD ISO Images
    • Linux Run Commands As Another User
    • How to Check PHP Version (Apache/Nginx/CLI)
    • How To Install and Configure GitLab on Ubuntu 20.04
    • How to Install PyCharm on Ubuntu 20.04
    • How to Check Ubuntu Version with Command or Script
    • How to Set all directories to 755 And all files to 644
    © 2013-2021 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy