Skip to content

Instantly share code, notes, and snippets.

@idleberg
Last active September 2, 2024 06:59
Show Gist options
  • Save idleberg/24479f34dc5007e50d47 to your computer and use it in GitHub Desktop.
Save idleberg/24479f34dc5007e50d47 to your computer and use it in GitHub Desktop.
Install Mcrypt on macOS

Setup php-mcrypt on macOS (and versions of Mac OS X)

These steps should have been mentioned in the prerequisites of the Laravel Installation Guide, since I'm surely not the only person trying to get Laravel running on macOS.

Install

Install Mcrypt using Homebrew and PECL (comes with PHP)

# PHP 7.3
$ brew install mcrypt
$ pecl install mcrypt-1.0.3

Find your php.ini:

$ php -i | grep "Loaded Configuration File"
Loaded Configuration File => /usr/local/etc/php/7.3/php.ini

Add this line to your php.ini:

extension=/usr/local/Cellar/php/7.3.x/pecl/20180731/mcrypt.so

Historic Answer

Install Mcrypt using Homebrew

# PHP 7
$ brew install php70-mcrypt

# PHP 5
$ brew install php56-mcrypt --without-homebrew-php

Add this line to /private/etc/php.ini:

# PHP 7
extension="/usr/local/Cellar/php70-mcrypt/7.0.x/mcrypt.so"

# PHP 5
extension="/usr/local/Cellar/php56-mcrypt/5.6.x/mcrypt.so"

You are ready to go!

Upgrade

Upgrade Mcrypt using Homebrew

$ brew reinstall -fs php71-mcrypt
@yourfriend5340
Copy link

Try the following steps found here. I setup my PHP using brew tap shivammathur/php.
My PHP version 7.0 however in the link you can install other PHP versions.

  1. brew tap shivammathur/extensions
  2. brew install shivammathur/extensions/[email protected]

Happy coding!

I tried this for [email protected], but it's not clear what is the next step to get mcrypt working? I tried pecl install mcrypt <5.6 mcrypt dir> but didn't work? See below:

————

==> Downloading https://ghcr.io/v2/shivammathur/extensions/mcrypt/5.6/manifests/5.6.40-2
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/shivammathur/extensions/mcrypt/5.6/blobs/sha256:7199e2f4e75f74f3dbc9f83625aea9732d1da
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:7199e2f4e75f74f3dbc9f83625aea9732d1
######################################################################## 100.0%
==> Installing [email protected] from shivammathur/extensions
==> Pouring [email protected]_monterey.bottle.2.tar.gz
Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /opt/homebrew
Could not symlink bin/libmcrypt-config
Target /opt/homebrew/bin/libmcrypt-config
is a symlink belonging to mcrypt. You can unlink it:
  brew unlink mcrypt

To force the link and overwrite all conflicting files:
  brew link --overwrite [email protected]

To list all files that would be deleted:
  brew link --overwrite --dry-run [email protected]

Possible conflicting files are:
/opt/homebrew/bin/libmcrypt-config -> /opt/homebrew/Cellar/mcrypt/2.6.8/bin/libmcrypt-config
/opt/homebrew/include/mcrypt.h -> /opt/homebrew/Cellar/mcrypt/2.6.8/include/mcrypt.h
/opt/homebrew/include/mutils/mcrypt.h -> /opt/homebrew/Cellar/mcrypt/2.6.8/include/mutils/mcrypt.h
Error: Could not symlink include/php/TSRM/TSRM.h
Target /opt/homebrew/include/php/TSRM/TSRM.h
is a symlink belonging to [email protected]. You can unlink it:
  brew unlink [email protected]

To force the link and overwrite all conflicting files:
  brew link --overwrite [email protected]

To list all files that would be deleted:
  brew link --overwrite --dry-run [email protected]

ap@MacBook-Pro ~ % pecl install mcrypt <<<"$(ls -d $(brew --prefix)/Cellar/[email protected]/* | tail -1)"
pecl/mcrypt requires PHP (version >= 7.2.0, version <= 8.2.0, excluded versions: 8.2.0), installed version is 5.6.40
No valid packages found
install failed

So, I temporarily switched to using php 7.4 and tried running again and...

pecl/mcrypt is already installed and is the same as the released version 1.0.5
install failed

Has anyone got this working recently for 5.6?

hi,bro
I have the same problem, and i resolved it...

1.brew tap shivammathur/extensions
2. brew search mcrypt(it will show "shivammathur/extensions/[email protected]" in the list)
3. brew install shivammathur/extensions/[email protected]

you will fine mcrypt.so in the "/usr/local/[email protected]/5.6.40"

@idleberg
Copy link
Author

Support for PHP 7.x runs out in just a few days, you can't be serious about still using 5.x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment