9

I am trying to update laravel using composer update on ubuntu 06.04 but everytime i run composer update this warning always comes up.

PHP Warning:  PHP Startup: Unable to load dynamic library 'mcrypt.so' (tried: /usr/lib/php/20170718/mcrypt.so (/usr/lib/php/20170718/mcrypt.so: cannot open shared object file: No such file or directory), /usr/lib/php/20170718/mcrypt.so.so (/usr/lib/php/20170718/mcrypt.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0

Does anyone knows how to deal it?

I am using php7.2

Fil
  • 8,225
  • 14
  • 59
  • 85
  • 2
    [mcrypt was deprecated in PHP 7.1 and moved to PECL in PHP 7.2](http://php.net/manual/en/migration71.deprecated.php). New code should use OpenSSL if possible. Are you sure you need mcrypt? – ChrisGPT was on strike Apr 19 '18 at 23:35
  • 2
    mcrypt is deprcated and hasn't been maintained for *years*. Don't use it. – Sammitch Apr 19 '18 at 23:35
  • I'm not sure I needed it. But the problem is when running composer it always shows up – Fil Apr 20 '18 at 00:07
  • I check on apache2/php.ini.. its not there. I dont know it is being initiated – Fil Apr 20 '18 at 00:07
  • https://stackoverflow.com/questions/16830405/laravel-requires-the-mcrypt-php-extension – Indra Apr 20 '18 at 12:15

6 Answers6

10

I faced similar issue when I installed Php7.2 on Ubuntu 18. Though I had installed mcrypt using PECL still I get the error mentioned in the question.

I did following to fix it

sudo apt-get install php-pear php7.2-dev

then uninstalled

pecl uninstall mcrypt

Now reinstall mcrypt

sudo apt-get -y install gcc make autoconf libc-dev pkg-config
sudo apt-get -y install libmcrypt-dev
sudo pecl install mcrypt-1.0.1

When you are shown the prompt

libmcrypt prefix? [autodetect] :

Press [Enter] to autodetect.

After success installing mcrypt using pecl, you should add mcrypt.so extension to php.ini.

The output will look like this:

...
Build process completed successfully
Installing '/usr/lib/php/20170718/mcrypt.so'    ---->   this is our path to mcrypt extension lib
install ok: channel://pecl.php.net/mcrypt-1.0.1
configuration option "php_ini" is not set to php.ini location
You should add "extension=mcrypt.so" to php.ini

Now restart Apache

sudo service apache2 restart

Grab installing path and add to cli and apache2 php.ini configuration.

sudo bash -c "echo extension=/usr/lib/php/20170718/mcrypt.so > /etc/php/7.2/cli/conf.d/mcrypt.ini"
sudo bash -c "echo extension=/usr/lib/php/20170718/mcrypt.so > /etc/php/7.2/apache2/conf.d/mcrypt.ini"
Mukesh
  • 7,630
  • 21
  • 105
  • 159
5

First, open up a terminal window and install the necessary dependencies with the commands:

sudo apt-get -y install gcc make autoconf libc-dev pkg-config
sudo apt-get -y install php7.2-dev
sudo apt-get -y install libmcrypt-dev

Once the dependencies have been installed, you can install mcrypt with the command:

sudo pecl install mcrypt-1.0.1

And there you go. Mcrypt is now installed. Go back to the process of installing whatever server software that depends upon this extension and you should be good to go.

Jitendra
  • 584
  • 1
  • 10
  • 28
  • 1
    I get the same err on `sudo pecl install mcrypt-1.0.1` – Elia Weiss Apr 14 '19 at 16:39
  • Notice: Trying to access array offset on value of type bool in PEAR/REST.php on line 187 PHP Notice: Trying to access array offset on value of type bool in /usr/share/php/PEAR/REST.php on line 187 Notice: Trying to access array offset on value of type bool in PEAR/REST.php on line 187 PHP Notice: Trying to access array offset on value of type bool in /usr/share/p hp/PEAR/REST.php on line 187 pecl/mcrypt requires PHP (version >= 7.2.0, version <= 7.3.0, excluded versions: 7.3.0), installed version is 7.4.8 No valid packages found install failed – stevenbranigan82 Jul 15 '20 at 23:59
4

For (>= PHP 7.3) you can use the following command:

sudo pecl install mcrypt-1.0.2
Sandeep
  • 41
  • 2
2

I faced this problem when I upgraded my PHP to 7.3

I found mcrypt.so was still present in /etc/php/7.3 that should not be as it is deprecated in php 7.3 so just deleting mcrypt.so from /etc/php/7.3 solved issue.

I used following commands:

cd /etc/php/7.3

sudo rm -rf mcrypt.so

sudo service apache2 restart

shivanisdev
  • 687
  • 6
  • 16
1

İts is worked for me.

export LC_ALL="C"

export LANG="C

sudo pecl install mcrypt-1.0.1

1

Also, if you're using php 7.2 & are getting this error and you know do not want/need mcrypt, but do not know how to exclude it.... You need edit your php.ini file and either comment this out by using a semi-colon in front of it:

; extension=mcrypt.so

or just delete that line entirely.

Nick
  • 138,499
  • 22
  • 57
  • 95
James Burnett
  • 151
  • 1
  • 5