How to: Change Timezone in PHP
  • 30 Jun 2023
  • 1 Minute to read
  • Dark
    Light

How to: Change Timezone in PHP

  • Dark
    Light

Article summary

Most servers have a set timezone. Sometimes you will want a website or php scripts to run at a completely different timezone. This is how you would change the timezone for php.

For shared hosting:

In shared hosting, you won't have access to change the server's timezone, because this can affect other users. Therefore, you can only do so by placing a php.ini file in your website's public_html. You can use an FTP program to upload a php.ini or use the cPanel file editor utility in File Manager.

Create a file called php.ini in the document root of the website and edit the php.ini.
In the php.ini file enter the following value: date.timezone="Australia/Sydney"
This will set the timezone to Sydney.

Here's a list of available options for Australia: http://php.net/manual/en/timezones.australia.php

If you want to use a timezone for just a single script, instead of in general. You would do so by adding the below to your code:
<?php date_default_timezone_set("Australia/Sydney"); ?>

For a virtual or dedicated server:

When you have your own server and want to change the PHP timezone for the entire server, you can do so by simply changing the timezone in the server's php.ini. 

On a cPanel server, it's located at:

/usr/local/lib/php.ini

In that file, you'd place date.timezone="Australia/Sydney"





Was this article helpful?

Changing your password will log you out immediately. Use the new password to log back in.
First name must have atleast 2 characters. Numbers and special characters are not allowed.
Last name must have atleast 1 characters. Numbers and special characters are not allowed.
Enter a valid email
Enter a valid password
Your profile has been successfully updated.
ESC

Eddy AI, facilitating knowledge discovery through conversational intelligence