Changing Your Server's Time Zone

Changing the time zone that your server is set to is relatively simple and straight forward. In this tutorial, we will walk you through the steps of changing your time zone at both the server level and for PHP, the most common changes needed for a Linux web server. Please note that this guide was written for Red Hat based operating systems such as Red Hat Enterprise Linux, CentOS, Scientific Linux, and ClearOS just to name a few. You may need to change certain parts of this tutorial if you are using an operating system that is not a derivative of Red Hat. This guide is applicable to both VPS and Dedicated Server clients. Web Hosting clients cannot change the time zone of the server, which is set to MST/MDT depending on the time of the year.

1.) Login to your server as root and check your current time zone by running
date
The ending will tell you the current setting such as UTC

2.) Locate the time zone you wish to use by changing the working directory to the timezone directory:
cd /usr/share/timezone

3.) List the contents of this directory to find the main area you are in:
ls /usr/share/zoneinfo/

4.) Take note of the next directory you want to go to. If your time zone is located in the United States, you would use the America/ directory. Change to that directory:
cd America/
5.) Now list the contents of that directory to get the final file name you will use.
ls
6.) If the time zone you want to use is MST/MDT, you would select Denver. Take note of the names you found from this step and step 4. The format you will use is <Step 4 Directory>/<Step 6 Filename> removing <> for both

7.) Next overwrite your current timezone file. This is done by executing the following command:
cp /usr/share/zoneinfo/<Step 4 Directory>/<Step 6 File> /etc/localtime
8.) You will be prompted to confirm you wish to overwrite the current file. Press y and [Enter]

9.) Edit your system /etc/sysconfig/clock file and update the ZONE value with <Step 4 Directory>/<Step 6 File> within the quotation marks.
vi /etc/sysconfig/clock
10.) Upon entering the editing program vim, press the [Insert] key once to edit the file. Once you are done editing the file, press the [ESC] key and then type :wq to write and quit the program.

11.) Finally update your php.ini file if you have one. You can locate your php.ini file by running the following at the command line:
php --ini
12.) Next, edit your php.ini file with the path you learned using the program above, for example:
vi /usr/local/lib/php.ini
13.) Find the value date.timezone and replace the value inside the quotation marks with <Step 4 Directory>/<Step 6 Filename> just as you did with the /etc/sysconfig/clock file. Remember to press[Insert] to edit the file and when done, [ESC] and then :wq to write and quit vim.

14.) Restart Apache to have the changes take place (this may vary depending on how your system is setup:
service httpd restart
15.) Run the date program again to check your changes were saved:
date
You should now have the time zone abbreviation of the zone you updated your system to such as MST/MDT

There you have it, your server is now setup to the time zone you specified. Certain programs may have their own time zones settings which you will need to change but for most systems, this is all you need to do. If you need to update the time, check out our article, Synchronizing Your Server's Clock.

Rather Mean Servers do it for you? Not a problem, open a sales ticket with Mean Servers and we will ensure your time is synchronized and that the time zone is set to your desired locale. Please note that a small client help fee will apply unless you are a Enterprise Managed customer.
  • 145 Пользователи нашли это полезным
Помог ли вам данный ответ?

Связанные статьи

Setup Your Own Private VPN with PPTP

PPTP VPN IntroductionTired of being geo blocked and not being able to watch your favorite TV...

Protect DirectAdmin from Brute Force Attacks

A common method of gaining access over a server is to use a technique called a brute force...

Synchronizing Your Server's Clock

Synchronizing your server's clock is not very difficult as there is a program that can be ran by...

Installing CSF (ConfigServer Security & Firewall)

The CSF, ConfigServer Security & Firewall, is a powerful firewall that is made for Linux...

Change Domain in DirectAdmin

This tutorial was written for those wishing to change their domain when using DirectAdmin as...