How to Configure Time zone for LAMP or LEMP on Ubuntu Linux

ubuntu 3344434 640
ubuntu 3344434 640

When setting up a new LAMP or LEMP server, it’s always good to do it right the first time. When your servers are configured the first time correctly, you won’t have to revisit configuring basic tasks.

This post shows students and new users how to properly configure LAMP / LEMP time zone on Ubuntu 16.04 LTS servers.

Getting the server configured in the correct time zone and dates allows webmasters to get logs reports with correct dates and times, configure time-based configurations, and many more.

So, when setting up your new LAMP or LEMP server, the step below is a great place to start.

Setting Ubuntu Correct Time zone

When installing a Ubuntu server, you’re prompted to choose the correct time zone in which the server will operate. Unfortunately, some webmasters fail to select the correct time zone and breeze through the installation.

Suppose you want to set Ubuntu up at the correct timezone. Or confirm that it’s at the correct timezone, do the step below:

First, run the commands below to view all available time zones on the servers and how their city names are formatted.

sudo timedatectl list-timezones

That should give you something like the list below

Africa/Abidjan
Africa/Accra
Africa/Addis_Ababa
Africa/Algiers
Africa/Asmara
Africa/Bamako
Africa/Bangui
Africa/Banjul
Africa/Bissau
Africa/Blantyre
Africa/Brazzaville
Africa/Bujumbura
Africa/Cairo
.
.

Now scroll down the list until you find the timezone your server is in. also, take note of how it’s formatted. For example, New York is going to be America/New York.

When ready, run the commands below to set the server to the correct timezone.

sudo timedatectl set-timezone America/New_York

That should set the server to the city of New York timezone.

The same thing can be configured with the commands below.

sudo dpkg-reconfigure tzdata

This should give you the same list, but this time you can scroll down and select the timezone from the list easily.

ubuntu timezone

Either of the commands above should give you the same results.

Configure PHP / PHP-FPM with Time zone

Now that the server is set up with the correct timezone go and configure PHP or PHP-FPM with the same timezone.

For LAMP servers, run the commands below to open the Apache2 PHP default config file.

sudo nano /etc/php/7.0/apache2/php.ini

Then scroll down the list and change the line below to the New York timezone.

date.timezone = America/New_York

Save the file and reload Apache2.

sudo systemctl reload apache2.service

For LEMP servers, run the commands below to open the PHP-FPM config file.

sudo nano /etc/php/7.0/fpm/php.ini

Then scroll down the list and change the line below to the New York timezone.

date.timezone = America/New_York

Save the file and reload PHP-FPM

sudo systemctl reload php7.0-fpm.service

That’s it!

You may also like the post below:

Posted by
Richard W

I love computers; maybe way too much. What I learned I try to share at geekrewind.com.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: