Many Symfony bundles require the intl-php-extension. Unfortunately my MAMP-version lacks it. Here is how i got it to work.
First a list of missing things in osx/mamp when adding the intl extension:
- autoconf/automake/libtool
- icu (International Components for Unicode)
- php-source
I am not sure wth came over apple, but in newer versions of XCode they do not include the auto-tools anymore.
My strategy for building the intl-extension was using pecl. I opted for that because it is said to be configuration-less. Can’t believe it? Me neither. But i think its still a somehow convenient way to install php extensions (when you do not find a binary). Also i always install everything into /usr/local because i think think this is the place where things belong. Don’t forget to change the paths to your preferences.
Ok. Back to work.
Contents
Build Tools and ICU
install autoconf/automake/libtool/icu (many thanks to Jean-Sebastien) as root (this is system stuff, its ok to do that as root):
sudo bash cd /usr/local/src curl -OL http://ftpmirror.gnu.org/autoconf/autoconf-2.68.tar.gz tar xzf autoconf-2.68.tar.gz cd autoconf-2.68 ./configure --prefix=/usr/local make make install cd /usr/local/src curl -OL http://ftpmirror.gnu.org/automake/automake-1.11.tar.gz tar xzf automake-1.11.tar.gz cd automake-1.11 ./configure --prefix=/usr/local make make install cd /usr/local/src curl -OL http://ftpmirror.gnu.org/libtool/libtool-2.4.tar.gz tar xzf libtool-2.4.tar.gz cd libtool-2.4 ./configure --prefix=/usr/local make make install cd /usr/local/src curl -OL http://download.icu-project.org/files/icu4c/4.8.1.1/icu4c-4_8_1_1-src.tgz tar xzf icu4c-4_8_1_1-src.tgz cd icu/source ./configure --prefix=/usr/local make make install
Nice. Now you should have all the basics for compiling apple (purposely?) neglected and icu.
PHP source
mamp does not include the php-source. But – and i definitely like this – MAMP provides the source for customization. Very neat. They call it “MAMP components”. Grab the version you need from sourceforge. I needed 2.0.2 because my MAMP version was 2.0.5.
Follow these steps (adjusting your paths and versions):
- download the MAMP-components from sourceforge
- unpack them – you get a bunch of zips
- locate the PHP-version you are using (i was using 5.3.6 as of writing this post)
- locate your MAMP-PHP-folder. Mine was located in /Applications/MAMP/bin/php/php5.3.6
- create an include/php folder inside this folder so that the following path is valid: /Applications/MAMP/bin/php/php5.3.6/include/php
- unpack the contents of the previously downloaded (mamp-components) php-5.3.6.tar.gz to this very folder.
- open a terminal and call the configure routine in this folder: ./configure –prefix=/Applications/MAMP/bin/php/php5.3.6
- happy pecl-ing!
ok – i did all this on the command line. so here is how my commands looked like (maybe this helps better than the list above – this time no sudo dudes, this is no system stuff!):
cd ~/Downloads unzip MAMP_components_2.0.2.zip cd /Applications/MAMP/bin/php/php5.3.6 mkdir include tar xzf ~/Downloads/MAMP_components_2.0.2/php-5.3.6.tar.gz -C include mv include/php-5.3.6 include/php cd include/php ./configure --prefix=/Applications/MAMP/bin/php/php5.3.6
We now have extended the basic MAMP-version with the php source code.
Finally install Intl-PECL extension
I did this after switching to the corresponding php-version folder.
cd /Applications/MAMP/bin/php/php5.3.6 ./bin/pecl install intl
The installation routine asks you for the location of your ICU installation. I answered /usr/local as location. Adjust this to your setup if you used different paths.
Enable the intl-extension in your php.ini by adding extension=intl.so to it. And don’t forget to restart MAMP.
That should have been it. HTH? Tell me in comments or contact me via twitter @gruzilla if you’re having troubles following this post.
Cleaning up
We do not need the files generated in /usr/local/src – but watch out, that you only delete what you created just now. Also the MAMP components in your Downloads folder can obviously be deleted.
Troubleshooting
Some of my friends encountered problems following the above guide. Here are some hints.
1) fatal error: ‘php.h’ file not found
Make sure you installed the MAMP-components correctly. Make sure the file php.h (and all files along with it) are in the correct place. The correct path would be:
/Applications/MAMP/bin/php/php5.3.6/include/php/main/php.h
Of course this might differ if you use another php-version.
2) Unable to detect ICU prefix or … failed. Please verify ICU install prefix and make sure icu-config works.
Now here we have two possibilities: a) you installed ICU in the wrong directory (wrong –prefix building icu) or b) you gave pecl the wrong answer where your ICU libraries are located.
- The correct prefix is /usr/local
- The correct answer is either /usr/local or /usr/local/ what ever workes for you
If you have built the ICU libraries in the wrong location (this happens when you give it some other prefix) you might want to uninstall it first by using make uninstall
.
3) My PHP binary wont find intl functions although everything else worked!
Ok – there can be multiple reasons to that.
- you might be using the wrong php-binary: execute
which php
in your terminal to check which binary is used. You can change this by altering your $PATH environment variable. Do not forget to restart your terminal. - you might have changed the wrong php.ini file. execute
php -i | grep php.ini
to check which php.ini is loaded by your binary and change correct file. - the intl.so file might not have been created in the correct location (or building might have failed) – check that the file exists. In my environment the file is located here: /Applications/MAMP/bin/php/php5.3.6/lib/php/extensions/no-debug-non-zts-20090626/intl.so
If you encounter any other problems, please let me know in the comments or contact me directly.
extension intl mamp osx php
Thank you.
Already spent 2 days looking for this problem. And your post is the only one with complete information how to fix this.
Thanks gus! Happy i could help!
This is the most helpful post I’ve been able to find on configuring MAMP PHP with the intl extension. Thank you so much!!!!!!!
Thanks Anthony for your kind words!
Am I being mental? I cannot find a configure file in any of the icu source packages..
@Tiff
Ohhh it’s OK – it’s cd icu/source
thanks for the amendment. i corrected it in the post!