How to change Timezone in PHP


Most servers have a set timezone and a lot of the time, 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.

First, create a file called php.ini in the document root of the website. Then, edit the php.ini.

In the file, put on a single line date.timezone="Australia/Sydney. This will set the timezone to Sydney.

Here's a list of available options for Australia:

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

For a virtual/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

Have more questions? Submit a request


Powered by Zendesk