This post shows students and new users how to configure LAMP / LEMP time zones properly on Ubuntu 16.04 LTS servers. Getting the server configured in the correct time zone 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.

Setting Ubuntu Correct Time zone

When you’re installing a Ubuntu server you’re prompted to choose the correct time zone in which the server is going to be operating. Some webmasters fail to select the correct time zone and just breeze through the installation. If you want to set Ubuntu up at 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 time zones on the servers and how their city names are formatted. That should give you something like the list below 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. That should set the server to the city of New York timezone. The same thing can be configured with the commands below. This should give you the same list, but this time you can scroll down and select the timezone from the list easily. 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. Then scroll down the list and change the line below to the New York timezone. Save the file and reload Apache2. For LEMP servers, run the commands below to open the PHP-FPM config file. Then scroll down the list and change the line below to the New York timezone. Save the file and reload PHP-FPM That’s it! You may also like the post below: