Php ini change timezone

If the incorrect time is in scripts, applications, or services on your server, you may find that resetting the timezone resolves the issue. In this article, we’ll show you how to set the timezone for PHP using My cPanel. 

Note: Traditionally, the timezone is set in the php.ini configuration file, but we do not allow direct changes to php.ini on HostPapa servers, so PHP configuration changes need to be made using My cPanel.

How to set the timezone for PHP

1) Log in to your HostPapa dashboard.

Php ini change timezone

2) Click on My cPanel or My WordPress.

Php ini change timezone

3) Scroll down to the Software section and click Select PHP Version.

Php ini change timezone

4) Click the Options tab.

Php ini change timezone

5) Click the value next to date.timezone to edit the timezone setting. You can view a complete list of alternative timezones worldwide on the

Your server's global time configuration cannot be changed, however, you can set the timezone for your website using or :

Setting up timezone via hPanel

Open Hosting → Manage → PHP Configuration page. There, open the PHP options tab and edit the date.timezone value:

Php ini change timezone

If you are not sure which time zone to insert, check the Time Zone Map.

Save the changes at the bottom of the page, and the timezone will be updated successfully 🚀

Setting up timezone via PHP function

As an alternative to the previous option, you can set the timezone using date_default_timezone_set PHP function. Just check the List of Supported Timezones, find the one which you need, and insert the following code to your website (in most cases, to index.php):

<?php
date_default_timezone_set("Asia/Bangkok");
echo date_default_timezone_get();
?>

NOTES: 

  • Don't forget to change "Asia/Bangkok" to the desired timezone

  • PHP documentation on date_default_timezone_set function

  • This change will affect only files. You can also apply a different time zone for the database (1 session)

    PHP relies on the date.timezone value for some date/time functions executed by php-based applications. Sometimes you even get an error message on your webserver logs that clearly indicates this necessity.


    Fortunately, this is easy to accomplish and we will show you how. For this guide, we will be using CentOS 6 with root privileges.


    Open the php.ini file


    On CentOS, the php.ini file is located at the /etc directory.

    sudo vi /etc/php.ini

    Depending on the installed version of PHP version, you will find a [Date] section like the following. If it is not there, just add a line with the "date.timezone = Your/Timezone" function.

    [Date]
    ; Defines the default timezone used by the date functions
    ; http://www.php.net/manual/en/datetime.configuration.php#ini.date.timezone
    date.timezone = 

    Uncomment the date.timezone function and set its value to the timezone you need. In this case we will use America/New_York. To see a list of supported timezones, refer to php.net

    You can configure PHP setting to use your local time zone by setting the date.timezone directive in php.ini.
    List of available time zones can be found here.

    Follow these instructions depending on the shared hosting plan you are using:

    for shared servers (Stellar, Stellar Plus plans and old Value, Professional, and Ultimate plans)
    for business servers (Stellar Business and old Business SSD packages)


    How to change 'date.timezone' on shared servers
     
    1. Go to your cPanel account >> the Files section >> the File Manager menu:

    Php ini change timezone


    2. Navigate to the root folder of your website (by default, it is public_html for the main domain and yourdomain.com for addon domains). If you don't have the php.ini file yet, feel free to create it using the "+ File"button:

    Php ini change timezone


    Right-click the file and select Code Edit:

    Php ini change timezone


    3. Add the following line:

    date.timezone = "Place/Your_town"

    change Place/Your_town to the preferred time zone:

    Php ini change timezone


    4. Click Save Changes.

    5. Next, add an LSPHP directive rule to your .htaccess file. You can learn more about the LSPHP handler here.
    Add the following lines to the .htaccess file (.htaccess is a hidden file. To see such files, click Settings in the upper right corner of the File Manager, check Show hidden files (dotfiles), then Save):

    Php ini change timezone


    Add the following line:

    lsapi_phpini /home/cPanel_user/public_html/php.ini


    Replace the cPanel_username with your actual cPanel username. If your php.ini file is located in a different directory, change the path accordingly:

    Php ini change timezone




    6. Click Save Changes.



    How to change 'date.timezone' on business servers

    Before editing/creating the php.ini file on a business server, you will need to check the PHP version that is set for the domain.

    1. Go to cPanel account >> the PHP Tweaks menu and select the domain from the drop-down menu. Check the PHP version used for this domain:

    Php ini change timezone


    2. Next, go to the Files section >> the File Manager menu:

    Php ini change timezone


    3. Enable Show hidden files (dotfiles) in the Settings menu:

    Php ini change timezone


    4. Navigate to /home/cPanel_user/.system-php/ini/PHP_ver/yourdomain.com (where PHP_ver is the PHP version used for the domain):

    Php ini change timezone


    5. If the php.ini file is not present in this folder, create it by using the "+ File" button:

    Php ini change timezone


    6. Right-click php.ini >> select Code Edit:

    Php ini change timezone


    7. Add the following line:
     
    date.timezone = "Place/Your_town"

    change Place/Your_town to the preferred time zone:

    Php ini change timezone


    Save the changes.



    That's it!




    Need any help? Contact our HelpDesk



    How to set default timezone in PHP ini?

    The date_default_timezone_set() function sets the default timezone used by all date/time functions in the script.

    What timezone is UTC for PHP?

    The default timezone for PHP is UTC regardless of your server's timezone. This is the timezone used by all PHP date/time functions in your scripts. See PHP's list of supported timezones to find the names of all possible timezones you can use for the date.

    How to get timezone in PHP?

    The date_default_timezone_get() function returns the default timezone used by all date/time functions in the script.

    How to change PHP timezone in Ubuntu?

    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.