17

I've successfully installed mcrypt via homebrew but I'm struggling to find the path to mcrypt.so to include it as an extension in php.ini.

mcrypt was installed at /usr/local/Cellar/mcrypt/2.5.8. Tree:

-- AUTHORS
|-- ChangeLog
|-- INSTALL_RECEIPT.json
|-- NEWS
|-- README
|-- TODO
|-- bin
|   `-- libmcrypt-config
|-- include
|   |-- mcrypt.h
|   `-- mutils
|       `-- mcrypt.h
|-- lib
|   |-- libmcrypt.4.4.8.dylib
|   |-- libmcrypt.4.dylib -> libmcrypt.4.4.8.dylib
|   `-- libmcrypt.dylib -> libmcrypt.4.4.8.dylib
`-- share
    |-- aclocal
    |   `-- libmcrypt.m4
    `-- man
        `-- man3
            `-- mcrypt.3

I tried to include mcrypt.h in php.ini:

extension="/usr/local/Cellar/mcrypt/2.5.8/include/mcrypt.h"

and then restarted apache. but it didn't work.

when I run php in the terminal I get:

PHP Warning:  PHP Startup: Unable to load dynamic library
'/usr/local/Cellar/mcrypt/2.5.8/include/mcrypt.h' - dlopen(/usr/local/Cellar/mcrypt/2.5.8/include/mcrypt.h, 9): 
image not found in Unknown on line 0
Matanya
  • 6,233
  • 9
  • 47
  • 80
  • Why is it installed there? – trojanfoe Jan 16 '13 at 11:19
  • That is where homebrew installed it... – Matanya Jan 16 '13 at 11:20
  • Is that what homebrew does with every package? I.e. rather than put libraries into `/usr/local/lib` it creates a directory for each? – trojanfoe Jan 16 '13 at 11:20
  • it seems like it keeps all the packages at `/usr/local/Cellar/[pkg_name]/[pkg_version]` – Matanya Jan 16 '13 at 11:23
  • I use macports and now I know why. That is much more sensible about installing packages. I would recommend ditching homebrew and trying macports instead... – trojanfoe Jan 16 '13 at 11:24
  • 4
    Homebrew works just fine. All you needed to do was to tap the recommended php formula, and install php from within Homebrew itself $ brew tap homebrew/dupes $ brew tap josegonzalez/homebrew-php $ brew install php54 $ brew install php54-mcrypt – Gazzer Jul 01 '13 at 10:17
  • Thanks @Gazzer. I believe it is better to add it as an answer – Matanya Jul 01 '13 at 10:49

6 Answers6

48

First check if brew is up-to-date:
brew doctor

Second install mcrypt based on php version:
brew install php53-mcrypt

NB: Step three below is not required on recent versions of brew:

Third open php.ini file and add reference:
sudo vi /private/etc/php.ini
extension="/usr/local/Cellar/php53-mcrypt/5.3.25/mcrypt.so"

Finally, restart apache:
sudo apachectl restart

Pete Thorne
  • 2,656
  • 4
  • 21
  • 29
pinxi
  • 543
  • 5
  • 6
  • 2
    For someone trying to only use homebrew this was useful. – Isaias Jan 29 '14 at 22:19
  • 2
    When I did `brew install php53-mcrypt`, brew told me it wasn't found, but mentioned a 'tap'. So I did `brew tap josegonzalez/php` to add that tap, and then ran `brew install php53-mcrypt` again, which installed a bunch of stuff, but eventually worked. – Tyler Collier Feb 27 '14 at 20:03
  • 4
    Today with recent versions of the softwares only `brew install php56-mcrypt` is necessary. – Simon Bengtsson Oct 05 '14 at 23:42
  • @TylerCollier Ditto over here. – Clive Portman Nov 17 '14 at 22:47
  • @SimonBengtsson - yep. I am using php 5.5 and got an error after adding `extension="/usr/local/Cellar/php55-mcrypt/5.5.30/mcrypt.so"` so removed it and everything works now. – But those new buttons though.. Nov 25 '15 at 17:16
  • `brew install php56-mcrypt` worked for me in Yosemite and also did not include the extension in php.ini. – pedalGeoff Dec 23 '15 at 18:39
  • Note, the reference to tapping josegonzalez above is out of date now, his work has now been made the official branch. `brew tap homebrew/homebrew-php` will get you what you need – Pete Thorne Feb 16 '17 at 08:04
22

After wondering for hours through different advices, this one worked for me (Installed via MacPorts):

Courtesy of Chris Brewer:

Download and install MacPorts from http://macports.org.

The following steps are performed in the Terminal:

Force MacPorts to update (will only work if Apple's Xcode installed):

sudo port -v selfupdate

Now, install memcached:

sudo port install php5-mcrypt

Copy the newly created shared object for mcrypt into Mac OS X’s default PHP5 extension directory:

sudo cp /opt/local/lib/php/extensions/no-debug-non-zts-20090626/mcrypt.so /usr/lib/php/extensions/no-debug-non-zts-20090626/

Next, you need to edit php.ini to add the extensions. Find the phrase Dynamic Extensions, and add:

extension=mcrypt.so

And finally, restart Apache:

sudo apachectl restart

webcoder
  • 129
  • 1
  • 10
Matanya
  • 6,233
  • 9
  • 47
  • 80
9

I've solved the problem with this

brew install php54-mcrypt --without-homebrew-php

Then I add this line to /etc/php.ini.

extension="/usr/local/Cellar/php54-mcrypt/5.4.24/mcrypt.so"

If this file doesn't exists you'll need to copy it from /etc/php.ini.default. Also I check the version of my php with php -v (And it was 5.4.x)

mariowise
  • 2,167
  • 2
  • 21
  • 34
0

I appreciate the work you did on this! This worked for me. I am on a mac and it was looking for xcode. The Developer location hadn't been set so I had to do all of this.

(RESOLVE THE DEVELOPER PATH) How can I resolve "Error: No developer directory found at /Developer"?

  1. sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer

(SIGN THE AGREEMENT TO USE XCODE)

  1. sudo xcodebuild -license

Lastly follow the above steps!

Community
  • 1
  • 1
SteckDEV
  • 489
  • 4
  • 13
0

Worked like a piece of cake with this.

$ brew install mcrypt
Warning: mcrypt-2.6.8 already installed
$ brew install php55-mcrypt
Warning: php55-mcrypt-5.5.20 already installed

Then test it out:

$ php -m | grep mcrypt
mcrypt

$ php -i | grep mcrypt
Additional .ini files parsed => /usr/local/etc/php/5.5/conf.d/ext-mcrypt.ini,
Registered Stream Filters => zlib.*, bzip2.*, convert.iconv.*, string.rot13, string.toupper, string.tolower, string.strip_tags, convert.*, consumed, dechunk, mcrypt.*, mdecrypt.*
mcrypt
mcrypt support => enabled
mcrypt_filter support => enabled
mcrypt.algorithms_dir => no value => no value
mcrypt.modes_dir => no value => no value
Harish Prasanna
  • 108
  • 1
  • 8
0

This may prove useful...

  1. brew tap homebrew/homebrew-php
  2. brew install php56-mcrypt
Oomta
  • 96
  • 6