Configure LAMP / LEMP Server Timezones on Ubuntu 16.04 LTS

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 correctly the first time,  you won’t have to revisit configuring basic tasks.

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

Getting the server configured in the correct timezone and with the correct 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.

Step 1: Setting Ubuntu Correct Timezone

When you’re installing a Ubuntu server you’re prompted to choose the correct timezone the server is going to be operating… some webmasters fail to select the correct timezone and just breeze through the installation..

If you want to set Ubuntu up with the correct timezone.. or confirm that it’s in the correct timezone, do the step below:

First, run the commands below to view all available timezones 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 you’re 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 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.

Step 2: Configure PHP / PHP-FPM with Timezone

Now that the server is setup with the correct timezone, go and configure PHP or PHP-FPM with the same timezone…

For LAMP servers, run the commands below to open 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 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:

Share Files on Ubuntu 16.04 LTS with Windows 10 Systems

Leave a Reply

Your email address will not be published. Required fields are marked *

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