48
votes

Trying to set up Laravel and keep getting hit with this error. I installed mcrypt through brew and it is located in /usr/local/Cellar. Any thoughts? .. It's not showing up in terminal command php -m either, if that matters. I'm running Mountaion Lion with macs native web server.

10
You need to recompile php againAmit Erandole

10 Answers

39
votes

You need to enable it in your php.ini file as well and probably restart Apache.

In php.ini you will find ;mcrypt.so and remove the ; from it.

Or, if it's not in there, just add mcrypt.so somewhere.

Also the salt option has been deprecated as of PHP 7.0.0. It is now preferred to simply use the salt that is generated by default.

66
votes

Ubuntu or any Debian based Linux users can install the required package with apt-get:

sudo apt-get install php5-mcrypt

Remember to restart the web server afterwards:

sudo service apache2 restart

If it still doesn't work, try to link the configuration file to the appropriate configuration folder for the web server. Thanks to dave1010 for this hint in the comments.

sudo ln -s /etc/php5/conf.d/mcrypt.ini /etc/php5/apache2/conf.d/   # for Apache
sudo ln -s /etc/php5/conf.d/mcrypt.ini /etc/php5/cli/conf.d/       # for CLI

And again, restart the web server:

sudo service apache2 restart

Perhaps, if not working yet, you need also the line showed by @RahulPrasad, with php5enmod mcrypt.

28
votes

Try sudo php5enmod mcrypt && sudo service apache2 restart

20
votes

You've installed mcrypt when you actually wanted the php56-mcrypt php module.

You stated in your question that you can see mcrypt installed in /usr/local/Cellar and that you're using OSX. So, the easiest way to install the mcrypt PHP module on OSX using Homebrew is:

// assuming you have php56
brew install php56-mcrypt

If homebrew can't find the correct package you may need to tap the PHP repositories found on GitHub:

brew tap homebrew/dupes
brew tap homebrew/versions
brew tap homebrew/homebrew-php

Now when you issue the command brew search mcrypt, you should see something like:

libtomcrypt   mcrypt   php53-mcrypt   php54-mcrypt   php55-mcrypt   php56-mcrypt

Several other posters have mentioned the need to edit your php.ini file. This will be unnecessary as homebrew will take care of activating the module for you. It places the configuration file at /usr/local/etc/php/5.6/conf.d/ext-mcrypt.ini

2
votes

You don't have the mcrypt PHP extension installed.

For a Mac, I followed these instructions: mcrypt on Mac 10.7 or 10.8.

They look like a lot, but it's not, it's very easy to follow in it works!

1
votes

You may have installed mycrypt but not have the php_mcrypt module installed / enabled.

1
votes

Just a note for people who have recently upgraded to PHP 7 - The MCRYPT library has been deprecated. If you upgraded to PHP 7 and are now seeing this error, that is why. You should switch to an alternative library, some alternatives are mentioned in this thread.

0
votes

Go to the CLI folder in your php instalation, and find php.ini in there and enable mcrypt. Terminal sometimes uses another php.ini, which is usually in the CLI folder.

0
votes

I installed php and mcrypt with Homebrew, but I still experienced this error after doing brew update a few times. I think my setup has just gotten a bit borked over time.

It turns out my php was being configured from /private/etc/php.ini, not /usr/local/etc/php/5.4/php.ini as Homebrew recommends. Mcrypt is not even being included from /usr/local/etc/php/5.4/ext-mcrypt.ini which doesn't make a lot of sense considering php -i produces this for me:

Configuration File (php.ini) Path => /usr/local/etc/php/5.4
Loaded Configuration File => /usr/local/etc/php/5.4/php.ini
Scan this dir for additional .ini files => /usr/local/etc/php/5.4/conf.d
Additional .ini files parsed => /usr/local/etc/php/5.4/conf.d/ext-mcrypt.ini

My solution:

  1. Edit /private/etc/php.ini as a superuser
  2. Add extension="/usr/local/Cellar/php54-mcrypt/5.4.28/mcrypt.so" and save
  3. Restart Apache with sudo apachectl restart
0
votes

This is what finally worked for me:

brew reinstall --with-homebrew-curl --with-httpd php56
brew reinstall --build-from-source php56-mcrypt

I also had to do sudo chmod 777 /usr/local/etc/php/5.6/conf.d because I got errors when the second brew reinstall tried to add the ext-mcrypt.ini to that directory.