Search code examples
phptimezonedb

How to use external timezondb for PHP8.1 instead of internal Mac OS


After the updating homebrew, I have an issue with timezonedb. Brew updated "Olson" Timezone Database Version, but it shouldn't be a problem because of timezonedb extension. The problem is: php uses the internal timezone db instead of external one.

Extension installation process:

  1. I installed this extension sudo pecl install timezonedb-2022.5, the version isn't the last, but I need it.
  2. I added it to the .ini file from the conf.d catalog: extension=timezonedb.so

For now if I run the command: php -i | grep -i timezone I received

"Olson" Timezone Database Version => 2022.7
Timezone Database => internal
Default timezone => UTC
date.timezone => no value => no value
timezonedb
Alternative Timezone Database => enabled
Timezone Database Version => 2022.5

It means, that the interpreter sees the installed extension but it is still using the internal database. How can I fix it and use the external one?

php version is 8.1, but I tried with different ones. Php was installed using homebrew + symlink for the particular version (brew install php@8.1 && brew link php@8.1). Other extensions work properly


Solution

  • I fixed it by manually downgrading the minor version PHP to 8.1.7. The guide is below:

    1. Download homebrew formulas (ruby config files) for PHP8.1.7 and icu4c dependency. It's the 72 version for php8.1.15 but must be 70 for php8.1.7 and it can't be installed automatically, because it tries to download the latest version.

    wget https://raw.githubusercontent.com/Homebrew/homebrew-core/f03637c77bc52f9fe497e23889db4563eb85299b/Formula/php.rb

    wget https://raw.githubusercontent.com/Homebrew/homebrew-core/f03637c77bc52f9fe497e23889db4563eb85299b/Formula/icu4c.rb

    1. Reinstall icu4c using the command brew reinstall icu4c.rb. Check the Cellar: /usr/local/Cellar/icu4c/. You should have the 70.1 catalog.

    2. Remove an old symlink rm /usr/local/opt/icu4c

    3. Create a new one: ln -s /usr/local/Cellar/icu4c/70.1 /usr/local/opt/icu4c

    4. Patch the ruby config for PHP. Remove depends_on "icu4c" to avoid downloading the last version of icu4c, save it

    5. Reinstall PHP brew reinstall php.rb. If it's not default, symlink it.