Install mcrypt PHP extension before install Yii2

When I installed Yii2, I got exception which terminated my installation.

Script yii\composer\Installer::postCreateProject handling the post-create-project-cmd event terminated with an exception

[Exception]

The mcrypt PHP extension is required by Yii2.

5993

Screen Shot 2014-10-16 at 7.47.54 AM.png

What’s mcrypt?

MCrypt is a replacement for the old crypt() package and crypt(1) command, with extensions. It allows developers to use a wide range of encryption functions, without making drastic changes to their code. It allows users to encrypt files or data streams without having to be cryptographers.

Yii2 using mcrypt to improved its crypt functions, so it’s one important PHP extension, and you cannot skip it.

I checked http://us1.php.net/manual/en/mcrypt.installation.php, and most comments is about Debian-based Linux system, and you can run the following commands to quickly install mcrypt:

sudo apt-get install php5-mcrypt

sudo /etc/init.d/apache2 restart

But I am using MacBook, so it gave me some trouble to install that. finally, I found very good article how to install mcrypt on MacOS.

If your MacOS is even older, you can refer to

Follow the steps exactly in the articles, you should be able to install mcrypt on your MacBook properly. See screen shots attached.5994

Screen Shot 2014-10-15 at 4.56.16 PM.png

I can’t run the init file,

"The mcrypt PHP extension is required by Yii2"

Using MAMP and phpinfo () says that mcrypt included.

I found this answer: "init uses the cli, but phpinfo shows cgi. In different php.ini connected and not connected mcrypt"

but how do I fix it?

I have never used Mac, but in Linux Ubuntu even if mcrypt is installed, sometimes you need to activate it manually with this command:




sudo php5enmod mcrypt



Maybe this will help.

Thanks. That help me!

Ps: don’t forget to restart your apache after enable the php5 mod


sudo apache2ctl graceful

Just in case someone had any troubles I did it like this :




sudo apt-get install mcrypt php5-mcrypt

sudo php5enmod mcrypt

sudo /etc/init.d/apache2 restart



For all those Yosemite users, I found the solution here: