I just started developing in Symfony2, and the installation told me I should install the Intl extension (intl.so) for internationalization. Although Symfony2 works without the extension, I suspect I will run into problems sooner or later, e.g. when using the translation service. So after trying some different ways to compile and install the extension, I finally found that it is fairly easy using Macports.
First, you need to install Macports (http://www.macports.org/install.php), which allows you to compile and install many Linux packages without any hassle.
Please note, if compiling for 32-bit version of MAMP, please read last section of this blog post (Wrong architecture) before continuing !
After installation, go to your terminal and run following command :
sudo port install php5-intl
This will take a while, and will install a whole lot of packages (even apache, php5, …). When this is done, copy the file /opt/local/lib/php/extensions/no-debug-non-zts-20090626/intl.so to the extensions dir of your MAMP application (for PHP5.3, this is /Applications/MAMP/bin/php5.3/lib/php/extensions/no-debug-non-zts-20090626) :
cp /opt/local/lib/php/extensions/no-debug-non-zts-20090626/intl.so /Applications/MAMP/bin/php5.3/lib/php/extensions/no-debug-non-zts-20090626/
Now, add the extension to your php.ini file :
# /Applications/MAMP/conf/php5.3/php.ini ... some stuff here extension=intl.so
Then (re)start your server, and the extension should be available (check phpinfo()). Have fun
Wrong architecture
If you get an error about wrong architecture, you have probably compiled everything in 64-bit while MAMP is compiled in 32-bit (and thus the extensions need to be in 32-bit as well). If so, edit the /opt/local/etc/macports/macports.conf file, and change (or uncomment) following line :
# /opt/local/etc/macports/macports.conf build_arch i386
From now on, macports will compile everything in 32-bit.
Hi Geert, could you please share compiled extension file for Snow Leopard? I tried to install mac ports and it demands xcode to be instaled — too much trouble for single extension.
Thank you
Hi Andrei,
I have placed the extension in following location :
http://blog.geertvd.be/blog_data/intl.so
After installing (copying) the extension, please check your error log file to see if php complains about missing header files (.h files). If it does complain, I’m afraid you’ll have to install XCode and macports anyway…
Good luck and let me know if you need any more help
Thank you for your post. Works great.
You’re welcome ! Has anyone tried to do this on OS-X Lion ? Should work as well, but I don’t have the time yet to test this… I know there is a new version of MAMP which runs on Lion, and that can run in both 32 and 64 bit.
Yes. I am running OS-X Lion 64 bit
works on Lion with MAMP 2.0.2 in 64 bit.
Cheers man!
I found another way to get the intl-extension to work, but this method is a bit less type-work, though it does get a lot of crap from macports (which i’m not too fond of, tbh).
Here’s the other way to do it – and this works equally well for any other php-extension:
The following is done for MAMP-2.0.2 with php-5.3.6 enabled, substitute for your php-version:
. This is needed by intl-extension, for other extensions you don’t need it: sudo port install icu
. Download MAMP_components from http://mamp.info/en/downloads/index.html
. extract the zip, unzip the correct php-version you’re using: tar -xzf php5.3.6.tar.gz
. Make an include folder: mkdir /Applications/MAMP/bin/php/php-5.3.6/include/php
. Move the just extracted php-source-folder to include: mv php-5.3.6 /Applications/MAMP/bin/php/php-5.3.6/include/php
. cd /Applications/MAMP/bin/php/php-5.3.6/include/php
. Configure that version: ./configure
. Install extension with pecl: pecl i intl
As I have tested under Lion environment (64-bit), Jo Giraerts method is not working. It will produce wrong architecture error.
I used macport method to compile intl.so and copy it to MAMP, and it is fine. But the one that compile with macport is under PHP 5.3.8 as indicated during the compile process. I don’t know if this will cause any problems afterward.
Good Luck !!
Hi Marco,
thanks for the update. I don’t think the .8 version will be a problem. I suspect only 5.2 or 5.3 could make a difference (not absolutely sure though…)
indeed. i’ve tried it again now (reinstalled lion) and it didn’t work out of the box.
But if you change the build_arch of ports as Geert stated in his ‘Wrong architecture’ addendum, all is well again.
Thanks for the great tutorial, I too needed it for Symphony. I’m up and running now.
Hi Geert,
Thanks for this… I found your site when searching for a way to bypass INTL for symfony2. I like MAMP Pro (Just trying to support them for the quality product they put together. I used Zend CE and it’s ok… but MAMP Pro is a lot more user friendly)
This option is MUCH better (compiling intl.so over using Zend CE)!
This has worked perfectly, on my OS 10.7.2 system.
This was the first time I’ve every played with MacPorts so it took about 20 minutes to compile… (Dependencies to be installed: icu php5 apache2 apr apr-util db46 expat libiconv gperf sqlite3 libedit ncurses ncursesw openssl zlib pcre bzip2 perl5 perl5.12 gdbm perl5 perl5 autoconf213 gawk gettext readline m4 gsed libtool automake autoconf help2man p5.12-locale-gettext libxml2 mhash pkgconfig glib2 libffi xz)
Overall though it was worth it. And to validate, I’m running 5.3.6 version of PHP under MAMP and the 5.3.8 version of the extension (intl.so) seems to be working fine so far.
There were no startup errors in the PHP console logs, and Symfony2 is not throwing any stub exceptions when I try to use and integer value for doctrine.
The error message I was trying to resolve was this one:
“The Symfony\Component\Locale\Stub\StubNumberFormatter::parse() method’s argument $type value 2 behavior is not implemented. Please install the ‘intl’ extension for full localization capabilities.” (More information on it here. https://github.com/symfony/symfony/issues/2735).
This was much better than waiting for a symfony developer to fix the stub, and it was better than installing Zend… very nice…
Thanks so much!
Sincerely,
Jay
Hi Jay (and others),
Thanks for the comments on my post. It is nice to see that my research (took me about 12 hours in total to get this thing compiled properly) is useful to others as well
Thank you very much, this helped me a lot!
Thank a lot for this great hint! Exactly what I was looking for. Now Symfony2 is working with MAMP 2.0.5 on my Mac.
Thank you, great hint worked like a charm on OSX Lion MAMP Version 2.0.3!!
I got the wrong architecture error. So after I made the change in macports.conf, should I uninstall php5-intl and then install again?
I’m not sure if you need to uninstall first, but I suggest you do. ‘sudo port uninstall php5-intl’ should do the trick (not tested myself).