Install PHP mcrypt extension on macOS

Sometimes you upgrade a legacy project that requires an old, deprecated extension like mcrypt. This extension doesn't come with PHP by default, so we have to install it via pecl.

pecl install mcrypt

Unfortunately, it doesn't work on my computer, and it keeps displaying this annoying error:

configure: error: mcrypt.h not found. Please reinstall libmcrypt.

So I found the solution on StackOverflow and decided to copy the command and write it here.

You can try this to save time when you have no idea what to do:

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