Install mcrypt and intl php extensions on Mac OS X and XAMPP

Category: Misc
Install mcrypt and intl php extensions on Mac OS X and XAMPP

Recently I downloaded and installed Magento 2 1.0.0-beta with composer on Mac OS X Yosemite. I’m using XAMPP as my webserver. When I tried to download Magento 2 sample data and all other dependencies I encountered two errors.

  • Problem 1 – The requested PHP extension ext-mcrypt * is missing from your system.
  • Problem 2 – The requested PHP extension ext-intl * is missing from your system.

ext-mcrypt ext-intl is missing from your sysmte

UPDATE: This solution works with Mac OS X Yosemite, but in El Capitan you will have to disable SIP. Read about modifying System Integrity Protection in El Capitan.

Problem 1 – Solving problem with mcrypt

PHP extension mcrypt “is an interface to the mcrypt library, which supports a wide variety of block algorithms such as DES, TripleDES, Blowfish (default), 3-WAY, SAFER-SK64, SAFER-SK128, TWOFISH, TEA, RC2 and GOST in CBC, OFB, CFB and ECB cipher modes. Additionally, it supports RC6 and IDEA which are considered "non-free". CFB/OFB are 8bit by default” - by php.net

XAMPP ships with built in mcrypt extension but the real problem is that when downloading dependencies with composer, it uses built in PHP version on your MAC and ignores XAMPP’s PHP. In order to continue you have to either install/enable mcrypt on your Mac or make an override in “.bash_profile”. When you make an override what you do is you replace native PHP of Mac with the one that you have installed with XAMPP. To do so, you have to include path to your PHP version in XAMPP.

  1. Open terminal application
  2. Enter “which php" and if it says “/usr/bin/php”, then proceed to step 3.
  3. Enter: sudo nano ~/.bash_profile
  4. Then paste this: export PATH="/Applications/XAMPP/xamppfiles/bin:$PATH"
  5. Ctrl+O then ENTER to save, then Ctrl+X to exit.
  6. Type: cd ~
  7. Type: . .bash_profile
  8. Restart terminal.
  9. Enter which php and if you did it right, it should be the same as the path in #4.

This solution was taken from Stackoverflow

Problem 2 – Solving problem with intl extenshion

The intl extension is an internationalization extension (referred as Intl) that is a wrapper for ICU library, enabling PHP programmers to perform UCA-conformant collation and date/time/number/currency formatting in their scripts. Intl extension is not included in XAMPP. So you have to install it manually.

Before you install intl you have to install Autoconf if you don’t have installed it yet. In your terminal execute following commands:

cd ~ && curl -O http://ftp.gnu.org/gnu/autoconf/autoconf-latest.tar.gz
tar -zxvf autoconf-latest.tar.gz
cd autoconf-2.69
./configure
make
sudo make install

NOTE: The files will be extracted to a directory named after the version of autoconf that was downloaded and may therefore differ from the above.

And now let’s install the intl extension. In your terminal issue the following command: sudo pecl install intl

When you are prompted for the location of ICU, simply enter “/usr/local” or simply hit return key. When the installation is finished you should add “extension=intl.so” into your php.ini file that should be located under “/XAMPP/xamppfiles/etc/” directory.

To check the location of your php.ini file in terminal issue command: “php --ini”

The last step is to clean up the temporary folder. To do so enter following commands:

cd ~ rm -rf autoconf-2.69

The solution for installing the PHP intl extension was taken from Coding Explained 

Conclusion

Hopefully this article will save your day, because for me finding solutions for this issues took a lot of time and effort. Finally, if you want to check which PHP extensions you have currently installed simply type “php -m” in terminal.