48

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.

coryj
  • 1,255
  • 3
  • 14
  • 29

10 Answers10

66

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.

Community
  • 1
  • 1
Sophy
  • 8,845
  • 6
  • 36
  • 30
  • Did the apt-get part and that my web server config was reloaded but needed a restart like Sophy mentions – Carlton May 21 '13 at 21:11
  • 8
    For some reason on Ubuntu, PHP wasn't picking up the mcrypt.ini. This fixed it: `sudo ln -s /etc/php5/conf.d/mcrypt.ini /etc/php5/apache2/conf.d/ ; sudo ln -s /etc/php5/conf.d/mcrypt.ini /etc/php5/apache2/conf.d/` – dave1010 Oct 31 '13 at 13:27
  • @dave1010 Yeah that did it, thank you very much!! But why the same command twice? – leemes Mar 30 '14 at 10:37
  • @leemes good spot. It should have been going into the `apache2` and `cli` directories (or whatever SAPIs you use): `sudo ln -s /etc/php5/conf.d/mcrypt.ini /etc/php5/apache2/conf.d/ ; sudo ln -s /etc/php5/conf.d/mcrypt.ini /etc/php5/cli/conf.d/` – dave1010 Apr 01 '14 at 16:02
  • @dave1010 Ah okay. I guess almost nobody noticed that mistake because most people use Apache :) – leemes Apr 01 '14 at 18:45
  • @dave1010 I hope it's okay that I copied this information into the answer so that future readers can spot it quickly. – leemes Apr 01 '14 at 18:52
  • 4
    For me the mcrypt.ini what at `/etc/php5/mods-available/mcrypt.ini`. I'm using Ubuntu 14.04 LTS and PHP 5.5.9-1ubuntu4.3. – frederickf Sep 04 '14 at 04:22
  • For Debian 9 and PHP 7 the needed package is `php7.0-mcrypt`. – arthropod Oct 26 '18 at 04:06
40

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.

Community
  • 1
  • 1
Deinumite
  • 3,979
  • 3
  • 25
  • 22
  • 4
    Didn't seem to work.. Found this line of code `code`[mcrypt] ; For more information about mcrypt settings see http://php.net/mcrypt-module-open ; Directory where to load mcrypt algorithms ; Default: Compiled in into libmcrypt (usually /usr/local/lib/libmcrypt) ;mcrypt.algorithms_dir= ; Directory where to load mcrypt modes ; Default: Compiled in into libmcrypt (usually /usr/local/lib/libmcrypt) ;mcrypt.modes_dir= `code` – coryj Sep 18 '12 at 15:45
  • This is what finally helped me if anyone else browsing has this same issue. Thank you guys for your quick responses! => http://www.coolestguyplanettech.com/how-to-install-mcrypt-for-php-on-mac-osx-lion-10-7-development-server/ – coryj Sep 20 '12 at 21:30
  • @coryjacik It depends on how you've compiled mcrypt, I should have specified that probably. – Deinumite Sep 22 '12 at 14:32
  • @coryjacik Thanks for the link, I followed that guide too. But even though on my system, autoconf was already installed, I had to `sudo ln -s /Developer/usr/share/autoconf /usr/share/` to get `/usr/share/phpize` working. – dualed Jan 12 '13 at 10:40
  • `mcrypt.so`?? phpinfo() say that my php.ini is ` /etc/php5/apache2/php.ini`, and there are **NO string "mcrypt.so"**! – Peter Krauss Feb 06 '15 at 13:53
  • 2
    new versions of debian/ubuntu are easier (and require) `apt-get install php5-mcyrpt`;, `php5enmod mcrypt`;, `service php5-fpm restart` – ppostma1 Jun 01 '15 at 20:14
  • By the way , `mcrypt_create_iv` is DEPRECATED in PHP 7.1.0. See `http://php.net/manual/en/function.mcrypt-create-iv.php` – slevin Oct 02 '17 at 13:59
28

Try sudo php5enmod mcrypt && sudo service apache2 restart

Rahul Prasad
  • 8,074
  • 8
  • 43
  • 49
20

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

darronz
  • 903
  • 9
  • 17
  • 2
    The PO should definitely use these solution to solve his problem... `brew` is the way to install packages on Mac OS X. – aymericbeaumet Aug 23 '13 at 22:06
  • This doesnt work for me... `Error: No available formula for php55 ` – theycallmemorty Mar 15 '14 at 20:05
  • This is the correct way to install `mcrypt` and also remember after run this command `brew search mcrypt` you want to install mcrypt using `brew install php56-mcrypt` – hash Jun 03 '15 at 06:41
2

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!

duality_
  • 17,738
  • 23
  • 77
  • 95
1

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

Andrew
  • 12,617
  • 1
  • 34
  • 48
1

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.

James Paterson
  • 2,652
  • 3
  • 27
  • 40
0

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.

Kris
  • 1
0

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
user110857
  • 2,023
  • 1
  • 21
  • 33
  • 1
    It actually does make sense, the PHP you use at the command line (cli) can use a different php.ini than the PHP your webserver uses, you should make a phpinfo file and check what the webserver is using. – Jimmy Knoot Feb 19 '15 at 13:46
  • @JimmyKnoot Thanks, I wasn't aware. – user110857 Nov 24 '15 at 17:17
0

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.

Eric Norcross
  • 4,177
  • 4
  • 28
  • 53