Skip to content

Instantly share code, notes, and snippets.

@jeremywall
Last active August 31, 2022 21:32
Show Gist options
  • Save jeremywall/63f44d56910d718e44fece774c5ae715 to your computer and use it in GitHub Desktop.
Save jeremywall/63f44d56910d718e44fece774c5ae715 to your computer and use it in GitHub Desktop.
Install/Upgrade TZDB for PHP
1: Create a php file on the server called tz.php (can be in your user’s home folder) and add this 1 line of code to the file: <?php echo timezone_version_get() . "\n"; ?>
2: Now run that file with this command: php -f tz.php
3: If it outputs something like “0.system”, that means you have the default timezone db that shipped with PHP, in other words it’s old. If it's been updated it will return the TZDB version like 2022.2. The part after the dot maps to a letter of the alphabet so 2022.2 is the 2022b TZDB release. If you see 0.system go to the INSTALL section below. If you see a TZDB release version like 2022.2 go to the UPGRADE section below.
INSTALL
1: We need pecl which is part of PHP’s pear package: sudo apt-get install php-pear
2: Use pecl to install the timezonedb extension: sudo pecl install timezonedb
3: If you get errors about "phpize not found" then run the following before re-running the previous "sudo pecl install" command: sudo apt-get install php5-dev
4: After "pecl install timezonedb" completes take note of the final lines of the output for something like: "Installing '/usr/lib/php/20170718/timezonedb.so'" (this is the path to the timezonedb.so file that PECL installed and may be needed later)
5: Add "extension=timezonedb.so" to php.ini at both /etc/php/apache2/php.ini and /etc/php/cli/php.ini. The exact paths of these files may differ based on version numbers of PHP in the path.
6: Use the tz.php script from earlier to check the TZDB that PHP now sees with this command: php -f tz.php
7: Restart Apache so it sees the new extension.
UPGRADE
1: Use the following command to upgrade the TZDB extension: sudo pecl upgrade timezonedb
2: After "pecl upgrade timezonedb" completes take note of the final lines of the output for something like: "Installing '/usr/lib/php/20170718/timezonedb.so'" (this is the path to the timezonedb.so file that PECL installed and may be needed later)
3: Use the tz.php script from earlier to check the TZDB that PHP now sees with this command: php -f tz.php
4: Restart Apache so it sees the new extension.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment