How to Change the PHP Timezone for Your Website

In some circumstances, you might need to modify your PHP setup in a specific way. One of these adjustments entails modifying the timezone of your PHP script. When the time is shown inaccurately in scripts and programs, making that modification is helpful. Three techniques for modifying the timezone of your PHP script are discussed in this post.

How to Change PHP Timezone for Your Website via the PHP Selector in cPanel

PHP configuration changes can be made from cPanel by following these steps:

  • Log in to cPanel.
  • Look for the Software section and click on Select PHP version;
  • The PHP Selector is not always included by default in cPanel. So, if you are not a FastComet client, it might be missing from your account. If that’s the case, you should contact your hosting provider.

  • In the new window click on the Options button. Here you can locate the date.timezone, and select the value that you require.

Here’s a list of the Supported PHP Timezones. Note that the region from which you can choose the sub-locations (in this case America), by default corresponds to the region set in the configuration file of the PHP Selector. That is an inherited value from the region of the server your account is on - at least for FastComet customers.

If you wish to use a completely different region, you can go past the PHP Selector config by using any of other two methods. Lastly, if you encounter a difficulty with any of those actions, feel free to contact our technical team anytime via a ticket.

How to Change PHP Timezone for Your Website in the .htaccess File

The second method to change your date.timezone is in the .htaccess file, which can be accessed via File Manager in cPanel.

In the .htaccess file use SetEnv TZ <timezone> to set the enviromental value TZ

Examples:

        SetEnv TZ Asia/Manila

        SetEnv TZ America/Fort_Nelson

You can also set here the date.timezone PHP value with php_value date.timezone “<timezone>”

  php_value date.timezone "America/Cayenne"

To set the default timezone in a PHP file use the code:

  <? php 
  date_default_timezone_set('America/Denver');

  //
  ?>

You can also set in PHP the environmental variable TZ

  <?php
  putenv("TZ=Africa/Accra");
  ?>

If you are experiencing any difficulties, you should submit a ticket via your Client Area, and our technical support team will gladly assist you further.

  • PHP, PHP Timezone
  • 0 Kasutajad peavad seda kasulikuks
Kas see vastus oli kasulik?

Seotud artiklid

Do Website Transfers Affect SEO?

It's a well-known fact that Search Engine Optimization (SEO) is crucial for increasing the...

How to Change the Max Memory and Max Upload Limit

There are certain scenarios when you may be asked to make changes to your PHP configuration....

Why is phpinfo() Disabled and How to Enable It

Disabling the PHP function phpinfo() has a good reason behind it — security. The phpinfo()...

How to Make All .html Pages to Run as .php Files Using .htaccess

PHP can be extremely useful when used in conjunction with HTML to enhance the features of a...

How to Set the max_input_vars Directive for Your Entire Hosting Account

The PHP variable max_input_vars was introduced in PHP 5.3.9+ as a security measure to limit the...