How To Fix – Mcrypt PHP extension required in Laravel on Mac OS X (No MAMP)

Laravel PHP web framework requires certain libraries to function properly. One of these libraries is the mcrypt and the php-mcrypt (bridge between mcrypt and php). However, there is a good chance that you will run into issues while running Laravel if these libraries and the extensions are not properly installed.

When I got started with setting up Laravel on a Mac OS X Maverics development machine, i ran into this error which said: Mcrypt PHP extension required. This can be fixed easily - in two ways either by installing php54-mcrypt or the php55-mcrypt extension using homewbrew for mac or my manually compiling the php-mcrypt extension. The development machine has the pre-installed PHP on OS X maverics and not the one from a third party package installer like MAMP.

Step 1: Install mcrypt for Mac OS X Maverics using homebrew - this command:

sudo brew install mcrypt

Just in case you get a brew error while running this command, this will be the cowardly refusing to sudo error from brew, fix it and try the above command again.

Step 2: Install php-mcrypt extension using brew (based on your php version php 5.4 or php 5.5:

sudo brew install php55-mcrypt

or

sudo brew install php54-mcrypt

If you get errors like brew no available formula, then you will have to build the mcrypt extension for php manually which is a really easy step.

After you are done with above steps, you should now no longer see the Mcrypt PHP extension required error and you are all set to start your Laravel development.

Some sample outputs:

Debjit-Sahas-Mac-mini:app debjit$ brew install mcrypt
==> Installing mcrypt dependency: mhash
==> Downloading https://downloads.sourceforge.net/project/mhash/mhash/0.9.9.9/mhash-0.9.9.9.t
######################################################################## 100.0%
==> ./configure --prefix=/usr/local/Cellar/mhash/0.9.9.9
==> make install
Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink include/mhash.h
/usr/local/include is not writable.

You can try again using:
brew link mhash
==> Summary

If you encounter errors like the `brew link` step did not complete successfully or mcrypt.h not found then all you need to do is issue the following commands in your terminal:

sudo brew link mcrypt

if above does not work then try the following command:

sudo brew link --overwrite mcrypt

Once you restart Apache after following these steps, you will see the Laravel welcome message: You have arrived

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。