How to install PHP Intl module in MAMP
Tags: experience, mamp, php
Published: 2024-03-16 10:08:52

---
title: How to install PHP Intl module in MAMP
published: true
date: 2015-07-17 19:31:14 UTC
tags: Experience,MAMP,PHP
canonical_url: https://io.serendipityhq.com/experience/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](http://aerendir.me/?p=456).

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](http://aerendir.me/?p=466).

### Verify you’ve installed Autoconf

[Install Autoconf](http://aerendir.me/?p=463) 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](http://site.icu-project.org/download) 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
```

## 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
```

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
```

### 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](http://aerendir.me/?p=463) before you can run the Intl installation.

### Troubleshooting: php\_intl.lo […] ERROR: ‘make’ failed

As [pointed out here](http://codingexplained.com/operating-systems/mac/installing-php-intl-extension-os-x-mavericks#comment-71009), you have to [install XCode Command Line Tools and create symlinks between XCode and MAMP](http://aerendir.me/?p=466).

## 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
```

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
```

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
```

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](https://github.com/sebastianbergmann/money) written by Sebastian Bergman (yes, the one who wrote also PHP Unit!): it is the best library/[Value Object](http://aerendir.me/?p=396) 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](http://symfony.com/doc/current/components/intl.html): 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](http://www.php.net/manual/en/intl.configuration.php).

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
```

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
```

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
```

To solve the problem [you have to export the variable `DYLD_LIBRARY_PATH`](https://www.drupal.org/node/1158312#comment-4472404) adding it to your `.bash_profile` file:

```
sudo vi ~/.bash_profile
Password: •
```

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}
```

Then, [save the file](http://askubuntu.com/a/252772/364826), so FIRST press `Esc` on your keyboard to quit the `edit mode` and fallback to `command line mode`, then type:

```
:wp
```

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

[Reload the `.bash_profile` file](http://stackoverflow.com/a/4608197/1399706) typing:

```
$ source ~/.bash_profile
```

Type again

```
php i- | grep -i intl
```

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](https://io.serendipityhq.com/experience/how-to-install-php-intl-module-in-mamp/) proviene da [ÐΞV Experiences by Serendipity HQ](https://io.serendipityhq.com).