How to Set PHP Timezone Using .htaccess (hPanel’s File Manager + FTP)

How to Set PHP Timezone Using .htaccess (hPanel’s File Manager + FTP)

In this article, we will show you how to change the PHP date.timezone on your website using the .htaccess file. Let’s take a look!

Changing PHP date.timezone with .htacess File

Before we go any further, make sure you know which timezone you want to use for your site. You can refer to this manual for a list of available timezones.

How to Change PHP date.timezone Through hPanel

.htaccess is a file located in public_html directory that you can edit using the File Manager on your Hostinger account, or via an FTP Client like FileZilla.

  1. Login to your hPanel and navigate to the File Manager under Files.File Manager highlighted on the hPanel left sidebar menu
  2. Scroll down and locate the .htaccess file. If it’s not available, click on Create a new file option in the upper part of the page.
  3. Right-click on the file and select Edit.
  4. Enter the following code at the very top of your .htaccess code:
    php_value date.timezone 'country/state'
    Editing date.timezone settings through the .htaccess file in hPanel

    Here we’re using “America/Chicago” as an example.

  5. Click Save & Close when you’re done.

How to Change PHP date.timezone Using an FTP client

You can also edit the .htacess file with an FTP client, such as FileZilla:

  1. Begin by configuring your FileZilla client.
  2. Connect to the server and find .htacess file, right-click and press View/Edit.Editing date.timezone settings through the .htaccess file in FileZilla
  3. Once the text editor pops out, use the same code from before: php_value date.timezone 'country/state'

    Click Save when you’re done.

  4. Check the “Finish editing and delete local file” option before clicking Yes.Confirming the changes done to the .htaccess file in FileZilla
  5. That’s it! The file will be uploaded to your server and you’ll be all set.

How to Verify If Your New Settings Are Live

To verify and see the changes you make, here’s what you can do:

  1. Create a new phpinfo.php file on public_html directory.
  2. Edit the file and insert the following code:
    <?php
    
    // Show all information, defaults to INFO_ALL
    
    phpinfo();
    
    ?>
  3. Save your changes. Open a new tab on your browser.
  4. Go to your website by adding phpinfo.php at the end of your URL.
  5. Scroll down to find the date.timezone information table.

Congratulations, you have successfully changed the time zone of your website!

Conclusion

Here’s how to change PHP data.timezone using .htaccess. In summary, there are two ways how you can accomplish this:

  1. Over your Hostinger account’s hPanel.
  2. Using an FTP client and editing the file.

That was pretty easy, right?

Author
The author

Elvinas S.

Elvinas is a senior server administrator at Hostinger. He monitors the infrastructure’s well-being and keeps the uptime at a maximum. Besides server management, web development has always been one of his biggest passions.