Installing the PHP intl extension on OS X Mavericks

Published on March 6, 2014 by

Sometimes one needs to use internationalization features in PHP. It might be that a library that you are using depends upon the PHP intl extension – for instance, some validators in Zend Framework 2 do so. This article will show you how to install the things you need by hand. It has been tested on OS X Mavericks with the built-in installation of PHP, but may or may not work on other setups. Please note that there are incredibly many ways to accomplish this, so this is merely my way of doing it. Please also note that this article is intended for OS X 10.9 Mavericks. Some of the steps are different for other versions of OS X, such as how to install Xcode.

Installing Xcode

First, we need to make sure that the Xcode Command Line Tools are installed. Begin by installing Xcode from the App Store if you do not have it installed already. Then open up a Terminal and enter the following: xcode-select –install. A popup dialog should be displayed with instructions on how to continue. Press the “Install” button and follow the instructions. If you have already done this in the past, you can simply ignore this step.

Enabling PECL and PEAR

We are eventually going to install the PHP intl extension with PECL, so we need to set this up so that we can fetch the extension from the repository. Fortunately, OS X ships with PECL and PEAR, although they are not enabled by default. Rather, Apple has provided a PHAR file for setting it all up. Issue the below commands in a Terminal window.

cd /usr/lib/php
sudo php install-pear-nozlib.phar

Now we need to add PEAR to the include path and specify the directory where extensions should be installed. This information should be added to the /etc/php.ini file. If you have defined a default editor for .ini files, you can simply enter open /etc/php.ini in the Terminal. Otherwise you can use vim, nano or similar, e.g. sudo vi /etc/php.ini or sudo nano /etc/php.ini.

If you do not have a /etc/php.ini file, then your PHP installation is using default settings. A default php.ini file is shipped with OS X and is located at /etc/php.ini.default. Enter the following command to copy it to /etc/php.ini so that it will be loaded by PHP.

sudo cp /etc/php.ini.default /etc/php.ini

Now you are ready to add the two lines to the PHP configuration file.

include_path = ".:/usr/lib/php/pear"
extension_dir = "/usr/lib/php/extensions/no-debug-non-zts-20100525"

Note: Be sure to double-check the extensions directory as it may differ depending on your version of OS X (if you are not using OS X 10.9 Mavericks). The date part differs in different versions of OS X.

Now let us make sure that our PEAR and PECL channels are up to date.

sudo pear channel-update pear.php.net
sudo pecl channel-update pecl.php.net
sudo pear upgrade-all

Installing ICU

The PHP intl extension depends on the ICU library that provides globalization support for software applications. Hence, we need to install this dependency. Note that when building the library, you will see a bunch of warnings, but simply ignore these and carry on.

cd ~ && curl -O http://download.icu-project.org/files/icu4c/52.1/icu4c-52_1-src.tgz
tar -zxvf icu4c-52_1-src.tgz
cd icu/source
./runConfigureICU MacOSX
make
sudo make install

The first of the above commands downloads version 52.1 of ICU. If you are using OS X Mavericks, then it is important to use this particular version (or newer), as you will otherwise get the following errors when compiling:

ld: 304 duplicate symbols for architecture x86_64
clang: error: linker command failed with exit code 1

You can find other versions of ICU right here.

Installing Autoconf

Now we need to install autoconf if you do not have it already.

cd ~ && curl -O http://ftp.gnu.org/gnu/autoconf/autoconf-latest.tar.gz
tar -zxvf autoconf-latest.tar.gz
cd autoconf-2.69
./configure
make
sudo make install

Note: The files will be extracted to a directory named after the version of autoconf that was downloaded and may therefore differ from the above.

Installing the PHP intl extension

Finally we are ready to actually install the PHP intl extension after having done the ground work! This is actually the easiest part.

sudo pecl install intl

When you are prompted for the location of ICU, simply enter /usr/local. Now add the following to your /etc/php.ini configuration file:

extension=intl.so

Note that if you do not have a /etc/php.ini file, then you need to copy a default configuration file to this location with the following command. Otherwise you can simply move on.

sudo cp /etc/php.ini.default /etc/php.ini

Once that is done, we need to restart Apache (or whichever web server you are using) for the changes to take effect.

sudo apachectl restart

Voilá! You should be good to go! Now you can either test an existing script that uses the intl extension if you have one, or verify that the extension is loaded with one of the two scripts below.

if (extension_loaded('intl')) {
	die('SUCCESS! The intl extension is enabled!');
} else {
	die('OOPS! The intl extension is not enabled!');
}
die(phpinfo()); // Search for "intl" in the generated output

Cleaning up

If you followed the steps in this article, then we have left a few temporary folders behind (sorry!). Let’s remove these folders from your home directory to keep things nice and clean.

cd ~
rm -rf icu
rm -rf autoconf-2.69

If you do not feel comfortable deleting the folders in the Terminal, then you can just as easily delete them in your home folder in Finder.

Author avatar
Bo Andersen

About the Author

I am a back-end web developer with a passion for open source technologies. I have been a PHP developer for many years, and also have experience with Java and Spring Framework. I currently work full time as a lead developer. Apart from that, I also spend time on making online courses, so be sure to check those out!

40 comments on »Installing the PHP intl extension on OS X Mavericks«

  1. Alex

    When I make command:

    sudo pecl install intl

    I get error:

    /private/tmp/pear/temp/intl/php_intl.h:23:10: fatal error: ‘php.h’ file not found
    #include

    What can I decide this problem?

    • Mihail

      I have the same issue with my MacOSX Maverics. I am using MAMP with PHP 5.4.19

      • benoit

        I had the same problem before
        You forgot the xcode-select –-install ?

        • moire

          This helped, thanks!

    • Joseph

      I’m having the same problem; also on Mavericks. Were you able to find a fix?

      • Coca

        You forgot the `xcode-select –-install` ?

  2. When I do the very first step:

    xcode-select –install

    I get:
    xcode-select: error: invalid argument ‘–install’

    any ideas?

    • maak.

      It reads “xcode-select –install”.
      The author’s tools automatically made an m-dash from the two simple dashes.
      Do you see the tiny difference between the dash and the m-dash in your post?
      Those anti-proportional fonts, that are used for displaying code-parts, almost always lack in that typographical aspect unfortunately.

  3. Ok, so I should have added that i am on the latest update of Mavericks, IDK if that makes a difference. I ignored the step i mentioned about xcode select complaining cuz i figured something might have changed recently. I went ahead and followed all the steps including downloading the newer version of ICU ( currently 53.1 ).

    Everything worked on the first try with no errors. Great article! I am happy to see this article as the 3rd result for “php ext intl mavericks”.

    • Great, I am happy that the article helped you. I will look into why you got the error with the xcode command, as I actually experienced the same thing while following this guide on a difference MacBook. Thank you for your comment and for sharing your results!

  4. Michael

    Thanks for this writeup. I got -> SUCCESS! The intl extension is enabled!

    You rock! :)

    • Great! I’m happy that everything worked out for you. Cheers! :-)

  5. foozy

    Hey bo, this is nice article. Personally i think you’re doing too much to install a simple extension. After installing the xcode, this can be done in 3 simple steps using homebrew:

    $ ruby -e “$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)”
    $ brew doctor
    $ brew install php55-intl

    • Hello foozy,

      You are right, but the reason I did it this way was that I have had limited success with homebrew and MacPorts in the past. Can you install extensions for the built-in PHP installation that ships with OS X, or do you have to make a separate installation of PHP through homebrew? If my memory serves me right, that’s what I ended up doing a year back, and it ended up getting a bit messy. I could be wrong, though.

      Thanks for your comment. :-)

    • Kuhan

      I did
      brew install php56-intl for php 5.6 , It works.

  6. sebastian

    nice tutorial, worked like a charm!
    thank you!!

  7. Marco Antônio Mafessolli

    When I run “sudo pecl install intl” i got this error:

    #include
    ^
    1 error generated.
    make: *** [php_intl.lo] Error 1
    ERROR: `make’ failed

    Did you get this same error? Do you know how can I resolve?

    • manpreet singh

      I am also getting the same error, every time I tried. Well anyway thanks for the article Bo Andersen, I appreciate really your efforts.

  8. AHHP

    Thanks. I had problem installing it.

  9. Aleksandra

    Thank You for this very clear and well written tutorial!

    • You are very welcome. Thank you for your feedback!

  10. Colin

    Thanks a million. Just needed the icu4c portion and it worked perfectly. Spent hours trying to figure it out before I came here.

    • You are welcome – I’m happy that you made it work! :-)

  11. Johan

    I followed the post and it worked perfectly with AMMPS in Yosemite. The one issue I had was with the ” xcode-select –install ” that was supposed to be ” xcode-select – – install ” but apart from that everything works like a charm.

  12. shon

    Dude this was perfect! TY for this, I’m not 100% sure of everything that was needed looking thru the terminal, but it got me up and running with a project needing php intl.

    Mad props!

  13. Serhiy

    If you are on OSX and using XAMPP, then you need to one step before doing any of the steps in the article:

    Check which php path is set i.e.

    root$: which php

    If you are using xampp on your mac it should be

    /Applications/XAMPP/xamppfiles/bin/php

    but if its

    /usr/bin/php

    you need to change your OSx php

    root$: PATH=”/Applications/XAMPP/xamppfiles/bin:${PATH}”

  14. Jialing

    This is awesome! I followed the steps to install PHP intl extension on my Mac OS X 10.11 El Capitan and it’s working. Thank you very much!

    • You are welcome! I am happy that you got it to work! :-)

  15. Vijay

    HI

    I am using OS X Yosemite 10.10 with XAMPP ,PHP Version 5.6.3,and CakePHP 3.0

    I have followed same steps that you listed over there but at the end I got this error”configuration option “php_ini” is not set to php.ini”

    And when I try to install it again getting this “pecl/intl is already installed and is the same as the released version 3.0.0
    install failed”

    I don’t know what I did wrong could you help me out how can I resolve this??
    Fatal error: You must enable the intl extension to use CakePHP.

    Regards
    Vijay

  16. Rosa

    How can I add the two lines to the PHP configuration file??? I am sorry I feel silly but I got stuck and I don’t know how to add these two lines. Could someone help me, please?

    • Hello Rosa,

      Sorry that this isn’t so clear in the post. First, open your php.ini file. The location varies depending on your setup, but is often located at /etc/php.ini on UNIX or OS X systems. Alternatively, if you are using MAMP, XAMPP or similar, you should look within their directories. The php.ini file can simply be opened in a text editor.

      I hope this helps. If you have any further questions, you are more than welcome to ask.

  17. intl module seems impossible to run on 10.11.6 (El Capitan), this procedure can be run but with no success… anyone can help?

  18. My error messege is composer related, i.e

    PHP Startup: Unable to load dynamic library ‘/usr/lib/php/extensions/no-debug-non-zts-20100525/php_intl.dll’ – dlopen(/usr/lib/php/extensions/no-debug-non-zts-20100525/php_intl.dll, 9)

    when I try to import any project. Same thing using .so extension instead…

  19. Antonio

    Hi

    I have followed all step with any problem, but now, i can´t restart my server, it stops itself and I have the same error that Salvatore. I have no idea how to fix it, even i have unistalled XAMP and install it again and the problem is.

  20. Rastak

    I got this error:
    tar -zxvf icu4c-52_1-src.tgz
    tar: Unrecognized archive format

Leave a Reply

Your e-mail address will not be published.