If you’ve ever typed
date into your Ubuntu Server and seen a different time or timezone appear than you expected, then it probably means that this tutorial is for you.
Check current timezone
Start by checking what data is returned using the following command:
In my case, I wanted to make sure my server’s time was in UTC, London. However, it was reported as being in Berlin.
Ubuntu uses symbolic files to link configurations for timezones.
So if you type
ls -l /etc/localtime, you will see why this configuration has been mapped:
Find our new timezone
We can get a list of all the available timezones by typing
I already know that I want
London, so let’s filter that list for the value first:
Set the new timezone
Next, we need to remove the symbolic link to the
localtime file and then relink it.
sudo unlink /etc/localtime
Now we can relink the file:
sudo ln -s /usr/share/zoneinfo/Europe/London /etc/localtime
At this stage, everything is set up, so let’s see it working:
Reload all scripts and servers
It’s now important to reload
Apache2 or any servers, or running scripts that had cached the date/time/timezone from before the change.
In my case, I will just kill all PHP scripts running and reload Apache2.