If your website is showing the wrong date or time — for example, order timestamps, blog posts, or logs appear hours ahead or behind — it’s because your PHP timezone is not yet configured.
Setting the correct timezone ensures that your website runs on your local time, keeping everything from invoices to scheduled tasks accurate.
Here’s how you can easily set any specific timezone (like Africa/Lagos
, Asia/Kolkata
, Europe/London
, etc.) using cPanel.
🔧 Method 1: Set Timezone Using .htaccess
(Recommended)
This is the easiest and most reliable way to set the timezone for your website in cPanel.
Steps:
- Log in to your cPanel account.
- Open File Manager.
- Go to your website folder — usually
/public_html
. - Find or create a file named
.htaccess
. - Add the following line at the end of the file:
How to Set Any Specific Timezone in cPanel Hosting php_value date.timezone "Your/Timezone"
Example:
php_value date.timezone "Africa/Lagos"
- Save the file and reload your website.
✅ Done! Your PHP scripts will now follow the timezone you’ve set.
You can confirm it by creating a file named phpinfo.php
in your public_html folder with this content:
<?php phpinfo(); ?>
Then visit yourdomain.com/phpinfo.php
and scroll to the date section — you’ll see your selected timezone.
⚙️ Method 2: Set Timezone via .user.ini
If you prefer, you can also use a .user.ini
file.
This method works perfectly on servers running PHP-FPM or LiteSpeed.
Steps:
- Go to your website folder in File Manager.
- Create a file named
.user.ini
. - Add the following line:
date.timezone = "Your/Timezone"
Example:
date.timezone = "Asia/Kolkata"
- Save the file.
- Wait for about 5 minutes and then refresh your website.
Your site will now use the timezone you specified.
💻 Method 3: Set Timezone Directly in PHP Code
For developers or advanced users, you can define the timezone in your PHP code directly.
Add this line at the top of your main PHP file (like index.php
):
<?php
date_default_timezone_set('Your/Timezone');
?>
Example:
date_default_timezone_set('Europe/London');
This ensures your application always uses the correct timezone, even if server settings change.
🕒 Why Setting the Correct Timezone Matters
- Accurate timestamps on invoices, forms, and emails
- Correct scheduling for cron jobs and automated tasks
- Proper record-keeping in logs and databases
- Better user experience for your local audience
Whether your website serves users in Africa, Asia, Europe, or America, setting the right timezone ensures smooth and accurate operations.
✅ Final Tip
You can find the complete list of valid timezone names here:
👉 https://www.php.net/manual/en/timezones.php
Simply copy your region’s timezone and use it in your .htaccess
, .user.ini
, or PHP code — for example:
America/New_York
, Asia/Dubai
, Africa/Lagos
, Europe/London
.
📌 In Summary
Method | File to Edit | Example Code |
---|---|---|
.htaccess |
Add in /public_html/.htaccess |
php_value date.timezone "Africa/Lagos" |
.user.ini |
Add in /public_html/.user.ini |
date.timezone = "Asia/Kolkata" |
PHP Code | Add in your main PHP file | date_default_timezone_set('Europe/London'); |
Setting the timezone correctly keeps your website’s clock accurate and ensures your business runs smoothly.