Skip to content
Follow
Ubuntu Linux

Setup PHP Timezone in Apache on Ubuntu 24.04

Richard
Written by
Richard
Feb 18, 2025 Updated Sep 15, 2026 3 min read
Setup PHP Timezone in Apache on Ubuntu 24.04
Setup PHP Timezone in Apache on Ubuntu 24.04

Setting the PHP timezone in Apache on Ubuntu 24.04 fixes incorrect timestamps by editing the central php.ini configuration file. This adjustment tells your website scripts the correct local time so your logs and scheduling tools match real life. On Ubuntu 24.04 running PHP 8.2 with Apache, you find this file at /etc/php/8.2/apache2/php.ini.

Advertisement
⚡ Quick Answer

Edit the php.ini file, typically found at /etc/php/[version]/apache2/php.ini. Uncomment or add the date.timezone line under the [Date] section and set it to your desired timezone, like America/Chicago. Restart Apache to apply the changes.

Advertisement

Set up Ubuntu timezone

Setting your Ubuntu timezone correctly is the first step to making sure your server’s time is accurate for PHP timezone setup Ubuntu tasks. You can check your server’s current timezone by running the timedatectl command in your terminal. This command shows your current local time, universal time, and time zone name so you know if you need to change it.

To find out which timezone your server’s is in or configured for, run the command below.

timedatectl

The command above should output a result similar to the one below.

               Local time: Tue 2025-02-18 14:51:49 CST
Universal time: Tue 2025-02-18 20:51:49 UTC
RTC time: Tue 2025-02-18 20:51:50
Time zone: America/Chicago (CST, -0600)
System clock synchronized: yes
NTP service: active
RTC in local TZ: no

There’s nothing to do if the server is in the correct time zone.

If not, you can use the steps below to change the server’s timezone.

Advertisement

First, list all the time zones available to your server by running the command below.

sudo timedatectl list-timezones

The command will output a list of all the time zones.

Africa/Abidjan
Africa/Accra
Africa/Addis_Ababa
Africa/Algiers
Africa/Asmara
Africa/Asmera
Africa/Bamako
Africa/Bangui
.....

Once you find the timezone to use, run the command below to set it up on your server.

sudo timedatectl set-timezone America/Chicago

Replace the highlighted Continent or Country/City in the command to match yours.

Advertisement
💡TipAlternatively, you can run the command below to select your server's time zone interactively.
sudo dpkg-reconfigure tzdata

Use the arrow up/down key to select the correct timezone.

Server timezone selection interface in Ubuntu 24.04
Server timezone selection interface in Ubuntu 24.04

The server's time zone should be updated.

Set PHP timezone

Updating your PHP timezone configuration ensures your web applications record the correct times. Open the php.ini configuration file for your specific PHP version by running sudo nano /etc/php/YOUR_PHP_VERSION/apache2/php.ini in your terminal. Scroll down to find the date.timezone setting, remove the semicolon in front of it, and type your correct city name.

Advertisement

To change or update the PHP timezone, run the command below to open each php.ini file at these locations.

Replace the highlighted version number (8.3) with the correct PHP version installed on the server.

sudo nano /etc/php/8.3/apache2/php.ini
sudo nano /etc/php/8.3/cli/php.ini

Update the [Date] section in the file.

[Date]
; Defines the default timezone used by the date functions
; https://php.net/date.timezone
date.timezone = America/Chicago

Save the file and exit.

Advertisement
💡TipAlternatively, run the command below to quickly update the timezone instead of digging through the php.ini file.
sudo sed -i "s/;date.timezone.*/date.timezone = America/Chicago/" /etc/php/8.3/apache2/php.ini
sudo sed -i "s/;date.timezone.*/date.timezone = America/Chicago/" /etc/php/8.3/cli/php.ini

Restart PHP to apply the settings.

sudo systemctl restart apache2

Verify the Configuration

Verifying your PHP timezone configuration confirms that your web server is using the correct time settings for your PHP timezone setup Ubuntu requirement. Create a test file named info.php in your web root folder with the code inside it. Open that file in your web browser and search the page for the date.timezone entry to check your changes.

   <?php
   phpinfo();
   ?>

Access this file through your web browser (http://localhost/info.php) and look for the date.timezone setting to verify it is set correctly.

Advertisement
Server timezone selection timezone
Server timezone selection timezone

That should do it!

Conclusion:

Setting the correct timezone in PHP with Apache on Ubuntu is crucial for ensuring that your applications accurately handle time-sensitive data. By following the steps outlined, you can:

  • Verify the server's current timezone and update it if necessary.
  • Make sure the PHP timezone aligns with the server's timezone for consistency.
  • Update the php.ini files or use command-line shortcuts for efficiency.
  • Restart the Apache server to apply the changes.
  • Verify the changes by checking the date.timezone setting with a PHP info page.

Ensuring that your system timezone is set correctly is vital for the reliability and accuracy of your web applications.

Was this guide helpful?

Was this helpful?
Richard

About the Author

Richard

Tech Writer, IT Professional

Richard, a writer for Geek Rewind, is a tech enthusiast who loves breaking down complex IT topics into simple, easy-to-understand ideas. With years of hands-on experience in system administration and enterprise IT operations, he’s developed a knack for offering practical tips and solutions. Richard aims to make technology more accessible and actionable. He's deeply committed to the Geek Rewind community, always ready to answer questions and engage in discussions.

Advertisement

📚 Related Tutorials

How to Enable or Disable Time Zone Automatic Setting in Windows 11
Windows How to Enable or Disable Time Zone Automatic Setting in Windows 11
Install Symfony 5 on Ubuntu with Apache
Ubuntu Linux Install Symfony 5 on Ubuntu with Apache
How to Set System Locale on Ubuntu 24.04
Ubuntu Linux How to Set System Locale on Ubuntu 24.04
How to Install Apache on Ubuntu Linux
Ubuntu Linux How to Install Apache on Ubuntu Linux

No comments yet — be the first to share your thoughts!

Leave a Comment

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