Tuesday, December 11, 2012

Installing the INTL extension on MAMP


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.


PS: related info

how to find is it 32bit or 64 bit

switch(PHP_INT_SIZE) {
    case 4:
        echo '32-bit version of PHP';
        break;
    case 8:
        echo '64-bit version of PHP';
        break;
    default:
        echo 'PHP_INT_SIZE is ' . PHP_INT_SIZE;
        break;
}

how to uninstall homebrew
https://gist.github.com/mxcl/1173223

how to uninstall macports
http://guide.macports.org/chunked/installing.macports.uninstalling.html

No comments: