How to Install PHP intl extension on OS X

Some PHP libraries that support internationalization depends on PHP intl extension. Somehow, intl extension is not installed by default. This article will show you how to install the intl extension. It has been tested well on OS X Yosemite with PHP 5.5.

1) Prerequisite

  1. Homebrew
  2. PECL
  3. Terminal

2) Install ICU Libraries via Homebrew

ICU is shorthand for International Component for Unicode. You can check the site here. We have to install this first.

$ brew update
$ brew install icu4c

3) Install Intl Extension via PECL

$ sudo pecl update-channels
$ sudo pecl install intl

You will be prompted in terminal the path where the extension is installed. Mine was

/usr/local/Cellar/php55/5.5.19/lib/php/extensions/no-debug-non-zts-20121212/intl.so

Here is my terminal screenshot after installation done.

Intl extension path in my system
Intl extension path in my system

Attention! You will probably get this error below when install intl

dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.54.dylib
Referenced from: /usr/local/bin/php
Reason: image not found

As solution, you need to execute the following command

$ brew upgrade php55

Then try to install intl again.

4) Add Intl Extension to php.ini

Check where your php.ini location is

$ php --ini

Open your php.ini and add the following line at bottom of file with your intl.so extension path (see its path on step 2)

extension=your-intl.so-extension-path

In my system, it was

extension=/usr/local/Cellar/php55/5.5.19/lib/php/extensions/no-debug-non-zts-20121212/intl.so

Save and quit the file

5) Restart Apache

After making changes on php.ini file, you need to restart apache.

$ sudo apachectl restart

6) Check the installation

There are two ways to check if our intl installation is success. First is using the following command

$ php -m | grep intl

The second way using phpinfo()

Check intl in phpinfo
Check intl in phpinfo

Summary

We are done installing intl extension for PHP. :)

  • PHP Guru

    This is super helpful, thanks! I did it with homebrew though `brew install php55-intl` then had to find the install path with find. I ended up adding the full path to the extension in php.ini:

    extension=/usr/local/Cellar/php55-intl/5.5.26/intl.so

    • deerawan

      you are welcome :)

  • Rujen Shakya

    I tried to do the command sudo pecl update-channels and i am getting this error.

    dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.55.dylib

    Referenced from: /usr/local/Cellar/php56/5.6.8/bin/php

    Reason: image not found

    I tried to upgrade php as well (also reinstall of php56), there is same problem.
    The php version i am running is 5.6.17 but in the reference from it is showing 5.6.8.

    Please help.

    • deerawan

      Probably because the php version is different. Have you tried to upgrade the PHP to 5.6.8?

  • santoso

    Halo, saya sudah mengikuti instruksi pd poin 2 dan berhasil, saya masih bingung setelah masuk ke web PECL,
    link apa saja yang harus saya donlod?
    krn saya tidak bisa masuk ke poin 3 spt langkah2 diatas.

    Mohon pencerahannya. thx.

    • deerawan

      Coba ikuti tutorial untuk install pecl di link ini => http://jason.pureconcepts.net/2012/10/install-pear-pecl-mac-os-x/

      • santoso

        Saya sudah mengikuti langkah2 spt link yg udh dsebutin dan berhasil
        cuma setelah saya balik lagi mengikuti poin 3 –> sudo pecl install intl

        saya mendapati error spt ini

        Kira2 apa yg harus diinstall lg?

        • deerawan

          Dari pesan errornya kemungkinan karena autoconf-nya ga ada. Coba install lewat brew

          $ brew install autoconf

          • santoso

            Thanks udh berhasil terinstal

  • Marcelo De Rezende Martins

    Hi,

    I had a problem when I was executing the command: sudo pecl install intl. The error was:

    Unable To Detect ICU Prefix Or … Failed. Please Verify ICU Install Prefix And Make Sure Icu-Config Works.

    I solved the problem with: brew link icu4c –force

    Thanks for posting,

    • deerawan

      Awesome!

  • hi trying to install pecl I got the following error:

    ld: file not found: libicudata.52.dylib for architecture x86_64
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    make: *** [intl.la] Error 1
    ERROR: `make’ failed

    I also made a brew cleanup but that didn’t solve my problem. Any idea? Thx in advance!

    • deerawan

      What is your PHP version?

      Have you tried to execute brew upgrade => brew upgrade php55

  • Kaldari

    When I try “sudo pecl install intl”, I get the error:
    could not extract the package.xml file from “/private/tmp/pear/download/intl-3.0.0.tgz”
    Download of “pecl/intl” succeeded, but it is not a valid package archive

  • In the end a brew reinstall php70 –with-pear, then a brew link icu4c –force followed by a sudo pecl install intl , but had the error In file included from /private/tmp/pear/temp/intl/php_intl.h:34:
    /private/tmp/pear/temp/intl/intl_error.h:24:10: fatal error: ‘ext/standard/php_smart_str.h’ file not found
    #include . Seems to be a PECL PHP 7 issue ( https://bugs.php.net/bug.php?id=71078 ) ..

    • mitchke

      it seems that ‘brew install php70-intl’ is enough.

  • Gerardo Vidal

    Thanks, Thank you very much. After trying solutions for 5 hours, I could install intl with your explanation.

  • Srinidhi Karnati

    Hi,

    I have tried using $ sudo pecl install intl and am getting the following error:

    Downloading intl-3.0.0.tgz …
    Starting to download intl-3.0.0.tgz (248,200 bytes)
    …………………………………………….done: 248,200 bytes
    ERROR: failed to write /usr/lib/php/pear/tests/intl/tests/_files/resourcebundle/.tmpes.res: copy(/usr/lib/php/pear/tests/intl/tests/_files/resourcebundle/.tmpes.res): failed to open stream: Operation not permitted

    I couldn’t figure this out. Please help. Thanks!

    • try `brew install php55-intl` or `brew install php71-intl` for php7.1. Works for me.

  • AbelardoLG

    Hi,
    After installing ‘sudo pecl update-channels’ this message was displayed:
    sudo: pecl: command not found
    but I don’t know how to fix it.

    Please, let me know how to do this.

    Kindest regards,
    Abelardo.