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.