DEV Community

Adamo Crespi for Serendipity HQ

Posted on • Originally published at io.serendipityhq.com on

How to install PHP Intl module in MAMP

Intl (Internationalization) Extension

[…] is a wrapper for » ICU library, enabling PHP programmers to perform » UCA-conformant collation and date/time/number/currency formatting in their scripts.

It is really useful, as, with it, you can, for example, manage currencies and money values in the simplest way possibile (examples at the end of this post).

It is also required by some advanced framework as Symfony to work with international values.

So, let’s install Intl PHP extension…

STEP 0: Before to start, verify your environment

Verify which version of PHP are you running in Terminal

Before you install ICU binaries, check that your Terminal is using the PHP binaries provided by MAMP.

Instead you have to install Intl both for the PHP used by Terminal – the one shipped with MacOSX – and for the PHP used by your browsers – the one shipped with MAMP. Yes, they are 2 separate binaries packages!

Verify you’ve Installed XCode and its Command Line Tools

Before you can install Intl binaries, you have to install xCode Command Line Tools.

Verify you’ve installed Autoconf

Install Autoconf so you can run the Intl installation (more about this later).

STEP 1: Download ICU binaries and uncompress them

Go to ICU Project download page and grab the latest version.

On the download page you’ll find binaries for the major platforms and the source code: be sure to download the source code , and NOT the binaries.

$ cd ~/Desktop
$ curl -O http://download.icu-project.org/files/icu4c/55.1/icu4c-55_1-src.tgz
$ tar xzvf icu4c-4_8_1_1-src.tgz
Enter fullscreen mode Exit fullscreen mode

STEP 2: Compile the binaries

Now that you have the ICU binaries, you have to install them. So, move into the icu/source folder and compile and install the binaries:

$ cd icu/source
$ ./runConfigureICU MacOSX
$ make && sudo make install
Enter fullscreen mode Exit fullscreen mode

This process may require some minutes and during the process you will be asked to provide the Admin password.

STEP 3: Install the ICU binaries

Now install the Intl binaries in PHP:

$ sudo pecl install intl
Enter fullscreen mode Exit fullscreen mode

Troubleshooting: Error “Cannot find autoconf”

If you receive an error that says something like

Cannot find autoconf. Please check your autoconf installation and the $PHP_AUTOCONF environment variable. Then, rerun this script.

then you have to install Autoconf before you can run the Intl installation.

Troubleshooting: php_intl.lo […] ERROR: ‘make’ failed

As pointed out here, you have to install XCode Command Line Tools and create symlinks between XCode and MAMP.

STEP 4: Add intl.so to your php.ini

Now the easy last part: activate your new Intl extension in your php.ini.

If you have configured you MacOSX Terminal to use the same PHP binaries of MAMP, then you have to go to /Applications/MAMP/bin/php/phpX.X.X/conf/php.ini.

To know which php.ini your Terminal is using, type in Terminal itself:

$ php -i | grep "php.ini"
Configuration File (php.ini) Path => /Applications/MAMP/bin/php/php5.6.6/conf
Loaded Configuration File => /Applications/MAMP/bin/php/php5.6.6/conf/php.ini
Enter fullscreen mode Exit fullscreen mode

So, open it with your favorite editor and find the line ; Extensions.

At the end of the section simply add the line extension=intl.so.

Now, save the php.ini and restart MAMP and verify that Intl extension is properly loaded:

$ php -i | grep "Internationalization support"
Internationalization support => enabled
Enter fullscreen mode Exit fullscreen mode

and, if you like, check also

$ php -i | grep "intl"
[...]
intl
intl.default_locale => no value => no value
intl.error_level => 0 => 0
intl.use_exceptions => 0 => 0
Enter fullscreen mode Exit fullscreen mode

Done! Now you have Intl library installed and working on your MAMP installation!

Now, let’s try Intl extension on the “battle field”

Now that you have Intl installed on your system, you can make great things with internationalization.

The first you can try is to install the Money library written by Sebastian Bergman (yes, the one who wrote also PHP Unit!): it is the best library/Value Object you can use to manage Money values. With it you’ll can manage, convert, perform math operations and many more on money values: Give it a try!

Another good thing to try is the Intl Component provided by Symfony Framework: really astonishing!

Finally, there is the last really, really important thing…

Configuring defaults for Intl extension

Now that we have installed Intl, we have to configure its default values.

So, open again your php.ini and find the line ; Module Settings ;: here there are configurations for all the modules used by PHP.

Add the following lines:

[intl]
intl.default_locale = en_utf8
intl.error_level = E_ALL
intl.use_exceptions = 1
Enter fullscreen mode Exit fullscreen mode

Again, run the command

$ php -i | grep "intl"
[...]
intl
intl.default_locale => en_utf8 => en_utf8
intl.error_level => 32767 => 32767
intl.use_exceptions => 1 => 1
Enter fullscreen mode Exit fullscreen mode

Now we have really all done: enjoy internationalization!

Troubleshooting

On startup (activate startup errors in PHP!), following this procedure, I’m getting a Warning:

Warning: PHP Startup: Unable to load dynamic library ‘/Applications/MAMP/bin/php/php5.6.6/lib/php/extensions/no-debug-non-zts-20131226/intl.so’ – dlopen(/Applications/MAMP/bin/php/php5.6.6/lib/php/extensions/no-debug-non-zts-20131226/intl.so, 9): Symbol not found: __ZN6icu_5513BreakIterator16getRuleStatusVecEPiiR10UErrorCode

Referenced from: /Applications/MAMP/bin/php/php5.6.6/lib/php/extensions/no-debug-non-zts-20131226/intl.so

Expected in: flat namespace

in /Applications/MAMP/bin/php/php5.6.6/lib/php/extensions/no-debug-non-zts-20131226/intl.so in Unknown on line 0

To reproduce the error, type in the Terminal this command:

php i- | grep -i intl
Enter fullscreen mode Exit fullscreen mode

To solve the problem you have to export the variable DYLD_LIBRARY_PATH adding it to your .bash_profile file:

sudo vi ~/.bash_profile
Password: •
Enter fullscreen mode Exit fullscreen mode

If you cannot edit the file, enter the Edit mode simply typing a.

Write in the file the DYLD_LIBRARY_PATH variable:

export DYLD_LIBRARY_PATH=/Applications/MAMP/Library/lib:${DYLD_LIBRARY_PATH}
Enter fullscreen mode Exit fullscreen mode

Then, save the file, so FIRST press Esc on your keyboard to quit the edit mode and fallback to command line mode, then type:

:wp
Enter fullscreen mode Exit fullscreen mode

A short hand could be to press SHIFT and the letter Z for two times.

Reload the .bash_profile file typing:

$ source ~/.bash_profile
Enter fullscreen mode Exit fullscreen mode

Type again

php i- | grep -i intl
Enter fullscreen mode Exit fullscreen mode

The error is gone away!

Remember to “Make. Ideas. Happen.”.

I wish you flocking users, see you soon!

L'articolo How to install PHP Intl module in MAMP proviene da ÐΞV Experiences by Serendipity HQ.

Top comments (0)