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:
- icu (International Components for Unicode)
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.
- 1 Build Tools and ICU
- 2 PHP source
- 3 Finally install Intl-PECL extension
- 4 Cleaning up
- 5 Troubleshooting
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/220.127.116.11/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.
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.
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.
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:
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
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 phpin 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.inito 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