Skip to content

Instantly share code, notes, and snippets.

@idleberg
Last active May 31, 2023 17:13
Show Gist options
  • Star 62 You must be signed in to star a gist
  • Fork 15 You must be signed in to fork a gist
  • 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
@markwallman
Copy link

brew install mcrypt
followed by
pecl install mcrypt-1.0.1

You may need to alter your php.ini file after this.

@FemkeBuijs
Copy link

@markwallman how do i need to update my php.ini file? I tried adding the path brew gave me (extension="usr/local/Cellar/mcrypt/2.6.8") but it still gives me 'Mcrypt PHP extension required.'

@ecedenyo
Copy link

same issue here with @FemkeBuijs

@minorsolis
Copy link

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!

@Iainmon
Copy link

Iainmon commented Nov 6, 2018

brew install mcrypt
followed by
pecl install mcrypt-1.0.1

You may need to alter your php.ini file after this.

Worked for me!

@MarGul
Copy link

MarGul commented Dec 12, 2018

brew install mcrypt
followed by
pecl install mcrypt-1.0.1

This worked for me.

@quannguyenbkat
Copy link

quannguyenbkat commented Jan 5, 2019

I hope this one can help someone
I have tried to install mcrypt with php7.1 but I got a warning "pecl/mcrypt requires PHP (version >= 7.2.0, version <= 7.3.0, excluded versions: 7.3.0)"
so I changed to php version 7.2 and run sudo pecl install mcrypt-1.0.1
after that, I switch to PHP 7.1 and it works
I'm using mac os v10.14 and apache environment

@leanwebstart
Copy link

If this can help someone... I did a lot of clean-up to get it to work... Now, first thing is start with a clean brew... that is,
brew doctor
is clean... all previous PHP are uninstalled and the actual directories cleaned up... then re-install 7.1 clean... then a simple
brew install mcrypt
will actually do the work and link the right pecl directory linked... That was a lot of work... but a great opportunity to clean up my mac... lol

@gagarine
Copy link

gagarine commented Feb 3, 2019

With macports:
sudo port install php71-mcrypt

@marcosrocha85
Copy link

I hope this one can help someone
I have tried to install mcrypt with php7.1 but I got a warning "pecl/mcrypt requires PHP (version >= 7.2.0, version <= 7.3.0, excluded versions: 7.3.0)"
so I changed to php version 7.2 and run sudo pecl install mcrypt-1.0.1
after that, I switch to PHP 7.1 and it works
I'm using mac os v10.14 and apache environment

I tried to do sudo pecl install mcrypt which tries to install mcrypt-1.0.2, but it fails on High Sierra on PHP 7.2. Using exactly sudo pecl install mcrypt-1.0.1 it did the trick.

@Yusov
Copy link

Yusov commented May 13, 2019

brew install mcrypt
php -i | grep 'Configuration File'
cd {config path}/php.ini
add  extension=mcrypt.so
sudo pecl install mcrypt-1.0.1
sudo apachectl restart

OS Mojave works perfectly

@daniel-esparragoza
Copy link

brew install mcrypt
followed by
pecl install mcrypt-1.0.1

You may need to alter your php.ini file after this.

For PHP 7.3, I installed mcrypt-1.0.2 as it supports PHP>=7.2 and PHP<=7.4
brew install mcrypt
pecl install mcrypt-1.0.2

I use Mojave and PHP 7.3. This works for me.
I didn't need to edit my php.ini, pecl did it automatically

@beporter
Copy link

Spotted a typo in the title: s/php-mycrypt/php-mcrypt/.

@ed-fruty
Copy link

ed-fruty commented Aug 1, 2019

php 7.2

brew install mcrypt
pecl install mcrypt-1.0.1

Pecl installation failed. I see, that my directory links was broken.

in /usr/local/Cellar/php@7.2/7.2.15/share/php@7.2/pear/System.php:294 I so that it try to create /usr/local/Cellar/php@7.2/7.2.15/pecl . In the fact it's a broken link to /usr/local/lib/php/pecl. That directory was not created. If you have something like thiis, you need to create another link, like:

cd /usr/local/lib/php && ln -s 20170718 pecl

@yamenarahman
Copy link

@skalero01
Copy link

php 7.3

brew install mcrypt
pecl install mcrypt-1.0.3

@lgelfan
Copy link

lgelfan commented Oct 27, 2019

for php 7.2 on High Sierra, similar to above, this worked for me:

brew install mcrypt
$(brew --prefix php@7.2)/bin/pecl install mcrypt

(you might need --force on the pecl install)

@linuxcarl
Copy link

no me funciona nada en laravel 4.2y php7.3 y mac os catalina

@linuxcarl
Copy link

@daniel-esparragoza puedes compartir tu php.ini

@daniel-esparragoza
Copy link

@generalistcodes
Copy link

With macports:
sudo port install php71-mcrypt

and where is the mcrypt.so located after this?

@Alfian5229
Copy link

With macports:
sudo port install php71-mcrypt

and where is the mcrypt.so located after this?

yes, help us captain

@subdesign
Copy link

If you use Laravel Valet, give a valet restart command after installing mcrypt so the system should recognise the lib.

@danmolina
Copy link

danmolina commented Nov 29, 2021

try pecl install mcrypt <<<"$(ls -d $(brew --prefix)/Cellar/mcrypt/* | tail -1)"

@roelvan
Copy link

roelvan commented Dec 1, 2021

Thanks @danmolina, worked!

@jovyllebermudez
Copy link

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