Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    You are at:Home»Programming»PHP»How to Setup Timezone in php.ini or PHP Script

    How to Setup Timezone in php.ini or PHP Script

    By RahulJune 5, 20191 Min Read

    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.

    Advertisement

    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");
    ?>

    datetime PHP time timezone
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    How to Install PHP 8.2-7.4 on RHEL & CentOS Stream 9

    Installing PHP on Pop!_OS

    How to Install PHP 8.x on Pop!_OS

    Managing Dependencies with Composer: A Beginner’s Guide

    Add A Comment

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • How to Install PHP 8.2-7.4 on RHEL & CentOS Stream 9
    • How to Install MySQL 8.0 on RHEL & CentOS Stream 9
    • How to Split Large Archives in Linux using the Command Line
    • System.out.println() Method in Java: A Beginner’s Guide
    • Split Command in Linux With Examples (Split Large Files)
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.