Getting mcrypt extension working on PHP 7.3.6 and Homebrew on Macbook

Robert Coster

Robert Coster

5 May 2021, 08:53

Getting mcrypt extension working on PHP 7.3.6 and Homebrew on Macbook

So got an extension to build and need to install a web app that uses Mcrypt. Unfortunately, there seems to be an issue with Mcrypt on MacBooks with Homebrew and PHP 7.3.

So how to get it running again?

Step 1

They tell you to use PECL to install. But if, like me, you get an error… Warning: mkdir(): File exists in /usr/local/Cellar/php/7.2.5/share/php/pear/System.php on line 294 ERROR: failed to mkdir /usr/local/Cellar/php/7.2.5/pecl/20170718

It feels like you can’t get past this point. However following along with a similar issue (article https://javorszky.co.uk/2018/05/03/getting-xdebug-working-on-php-7-2-and-homebrew/) it appears that it can’t create a directory. Looking in /usr/local/Cellar/php/7.3.6 you see that pecl is a symlink. Remove this symlink.

Step 2

Re-run the pecl install for mcrypt…. pecl install mcrypt-1.0.2. Success this time, the plugin is installed. Although don’t get over excited. There are more steps :(

Step 3

Find the path to your in-use php.ini file by issuing the command php --ini.

Step 4

Open this folder in an editor such as visual studio code (code . in the directory mentioned in php --ini)

Step 5

At the very top of your php.ini file in this directory will be a declaration for the installed mcrypt extension. Its wrong. It’ll say something like extension=“mcrypt.so” and will cause errors in PHP at the moment.

Step 6

Remove this line.

Step 7

Create an mcrypt.ini file in the conf.d directory. Write…

;mcrypt extension=”/usr/local/Cellar/php/7.3.6/pecl/20180731/mcrypt.so

…save the file.

Step 8

Restart the web server. If you are using Laravel Valet the command is…

valet restart

It should now be working and installed.


More Web Development & Laravel Posts

How to seed a geographical POINT using Laravel / MySQL

Guide: SSL Certificates

Guide: PHP Frameworks

Steps to Dokku and Postgres (with PostGIS) on Ubuntu 16.04

Guide: What is DNS?

Getting mcrypt extension working on PHP 7.3.6 and Homebrew on Macbook

Disabling Events in Laravel Model Observer

Guide: What is a domain name?