Skip to content

Instantly share code, notes, and snippets.

@idleberg
Last active May 31, 2023 17:13
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
@roelvan
Copy link

roelvan commented Dec 1, 2021

Thanks @danmolina, worked!

@jovylle
Copy link

jovylle commented Apr 27, 2022

Hi there! I solved this problem in Mac using Mojave. I had a Laravel mcrypt dependency. I did this:

  1. brew install httpd
  2. brew install php@5.6
  3. edit the http.conf (after installation it will tell you where's localted) and add that php version.
  4. In my case, I run it using the port 8080, so I configure it to be http://localhost:8080 that way I have both running (the default).
    mcrypt will be included, however, I did too many changes to you may also need to install mcrypt by doing this:
  • Also just in case (because I did too many things)
    If you still don't have mcrypt available, then:
  1. Install pecl
  2. sudo pecl install mcrypt-1.0.1

restart your brew apache using "sudo apachectl restart" and done!

pecl/mcrypt requires PHP (version >= 7.2.0, version <= 7.3.0, excluded versions: 7.3.0), installed version is 5.6.40
No valid packages found
install failed

above is my issue, it seems it no longer exist.

@j-carbaquil
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/mcrypt@7.0

Happy coding!

@ajmedway
Copy link

ajmedway commented Aug 18, 2022

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/mcrypt@7.0

Happy coding!

I tried this for php@5.6, 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 mcrypt@5.6 from shivammathur/extensions
==> Pouring mcrypt@5.6--5.6.40.arm64_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 mcrypt@5.6

To list all files that would be deleted:
  brew link --overwrite --dry-run mcrypt@5.6

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 php@5.6. You can unlink it:
  brew unlink php@5.6

To force the link and overwrite all conflicting files:
  brew link --overwrite php@5.6

To list all files that would be deleted:
  brew link --overwrite --dry-run php@5.6

ap@MacBook-Pro ~ % pecl install mcrypt <<<"$(ls -d $(brew --prefix)/Cellar/mcrypt@5.6/* | 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?

@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/mcrypt@7.0

Happy coding!

I tried this for php@5.6, 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 mcrypt@5.6 from shivammathur/extensions
==> Pouring mcrypt@5.6--5.6.40.arm64_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 mcrypt@5.6

To list all files that would be deleted:
  brew link --overwrite --dry-run mcrypt@5.6

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 php@5.6. You can unlink it:
  brew unlink php@5.6

To force the link and overwrite all conflicting files:
  brew link --overwrite php@5.6

To list all files that would be deleted:
  brew link --overwrite --dry-run php@5.6

ap@MacBook-Pro ~ % pecl install mcrypt <<<"$(ls -d $(brew --prefix)/Cellar/mcrypt@5.6/* | 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/mcrypt@5.6" in the list)
3. brew install shivammathur/extensions/mcrypt@5.6

you will fine mcrypt.so in the "/usr/local/mcrypt@5.6/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