Elthomson
Elthomson

Reputation: 51

How do I install mcrypt extension for php 7.1 on MacOS 12 for Laravel development?

This is driving me crazy and following all the online tutorials hasn't helped.

I have just upgraded to a new mac running MacOS Sierra (10.12.1) and am trying to get my development environment configured. However, whenever I run composer update or composer install on my project I get the following message:

PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib/php/extensions/no-debug-non-zts-20131226/mcrypt.so' - dlopen(/usr/lib/php/extensions/no-debug-non-zts-20131226/mcrypt.so, 9): image not found in Unknown on line 0
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Installation request for laravel/framework v5.0.35 -> satisfiable by laravel/framework[v5.0.35].
    - laravel/framework v5.0.35 requires ext-mcrypt * -> the requested PHP extension mcrypt is missing from your system.
  Problem 2
    - laravel/framework v5.0.35 requires ext-mcrypt * -> the requested PHP extension mcrypt is missing from your system.
    - tom-lingham/searchy 2.0.10 requires illuminate/support 5.* -> satisfiable by laravel/framework[v5.0.35].
    - Installation request for tom-lingham/searchy 2.0.10 -> satisfiable by tom-lingham/searchy[2.0.10].

  To enable extensions, verify that they are enabled in those .ini files:
    - /etc/php.ini

I have run brew install mcrypt and it is already installed.

Warning: mcrypt-2.6.8 already installed

The system is running php 7.1 so I have also run brew install php71-mcrypt

extension=mcrypt.so has been included in the php.ini files, both on my machine and I have tried it inside the vagrant machine.

Any help would be much appreciated as I have been at this for 2 days now!

Upvotes: 1

Views: 4280

Answers (2)

Andrii Vitsentovych
Andrii Vitsentovych

Reputation: 29

I had troubles of installing mcrypt-1.0.3 with PHP 7.1 on MacOS 12 Monterey.

 ~/projects/rest-api php -v      
PHP 7.1.33 (cli) (built: Jun  7 2022 17:45:50) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.1.33, Copyright (c) 1999-2018, by Zend Technologies

pecl install mcrypt-1.0.3 and pecl install --force mcrypt-1.0.3 failed with next error:

...
configure: error: mcrypt.h not found. Please reinstall libmcrypt.
ERROR: `/private/tmp/pear/temp/mcrypt/configure --with-php-config=/opt/homebrew/opt/[email protected]/bin/php-config --with-mcrypt' failed

But I managed to install it with next command:

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

Last lines of result:

...
Build process completed successfully
Installing '/opt/homebrew/Cellar/[email protected]/7.1.33_4/pecl/20160303/mcrypt.so'
install ok: channel://pecl.php.net/mcrypt-1.0.3
Extension mcrypt enabled in php.ini

~/projects/rest-api php -m | grep mcrypt                                                  
mcrypt

Please see solution source.

Upvotes: 1

pseudoanime
pseudoanime

Reputation: 1593

Since you are running vagrant, you need to install mcrypt within the vagrant machine. check which version of php you have installed on vagrant and install mcrypt using

sudo apt-get install *{mcrypt-version-here}*

restart apache using

sudo service apache2 restart

Upvotes: 1

Related Questions