43

Since Laravel4 requires mcrypt extension, and PHP7 doesn't seem to have mcrypt extension, is there any workaround for this to work?

Machavity
  • 30,841
  • 27
  • 92
  • 100
Bishal Paudel
  • 1,896
  • 2
  • 21
  • 28
  • 2
    You've tagged this Laravel 5.1, which is the newest version of Laravel. It does not require mcrypt to work. See http://laravel.com/docs/5.1/installation for reference of what you need. – Joel Hinz Dec 04 '15 at 08:05
  • 2
    You could install it? Usually that's the workaround when you're missing a library – Damien Pirsy Dec 04 '15 at 08:08
  • @JoelHinz I changed the to Laravel 4. – Bishal Paudel Dec 04 '15 at 08:16
  • @DamienPirsy Thanks, I will try installing it manually. – Bishal Paudel Dec 04 '15 at 08:17
  • if you're on centos https://webtatic.com/packages/php70/ – astroanu Dec 04 '15 at 11:26
  • It is best not to use mcrypt, it is abandonware, has not been updated in years and does not support standard PKCS#7 (née PKCS#5) padding, only non-standard null padding that can't even be used with binary data. mcrypt has many outstanding [bugs](https://sourceforge.net/p/mcrypt/bugs/) dating back to 2003. The mcrypt-extension is deprecated will be removed in PHP 7.2. Instead consider using [defuse](https://github.com/defuse/php-encryption) or [RNCryptor](https://github.com/RNCryptor), they provide a complete solution and are being maintained and is correct. – zaph Jun 12 '17 at 14:09

9 Answers9

85

Had the same issue - PHP7 missing mcrypt.

This worked for me. When asked, keep local PHP configuration files.

sudo apt-get update
sudo apt-get install mcrypt php7.0-mcrypt
sudo apt-get upgrade

Restart FPM (or Apache or NGINX etc.) after installation.

mindplay.dk
  • 7,085
  • 3
  • 44
  • 54
Ryderpro
  • 1,315
  • 10
  • 18
  • 3
    I had to do this first `sudo add-apt-repository ppa:ondrej/php` – user985366 Jun 01 '16 at 13:17
  • 2
    @user985366 thanks ...yes we have to do this `sudo add-apt-repository ppa:ondrej/php` and then `sudo apt-get update sudo apt-get install mcrypt php7.0-mcrypt sudo apt-get upgrade` and then it worked for me – Osama Al-Banna Aug 20 '16 at 14:33
  • @Ryderpro Do we need to install `mcrypt` when we're already getting `php7.0-mcrypt`? Or are they 2 diff things entirely? – enchance Dec 15 '16 at 11:57
29

I'm on Mac and with laravel valet I've solved with this:

brew install php70-mcrypt

carlituxman
  • 1,201
  • 12
  • 22
13

Even if you enable mcrypt in php.ini, this issue may occur. Try the following steps.

sudo apt-get update
sudo apt-get install mcrypt php7.0-mcrypt

I am working in ubuntu 16.04 and the following commands also helped me.

whereis php  -shows the files with this name
php -v   -shows the php version
which php -shows current php version that is running on the server
oldtechaa
  • 1,463
  • 1
  • 14
  • 26
Hemantha
  • 353
  • 2
  • 7
8

On ubuntu: According to launchpad.net the package for mcrypt is called php7.0-mcrypt.

sudo apt-get install php7.0-mcrypt to install

Sorin
  • 767
  • 12
  • 17
4

Open terminal with Ctrl + Alt + T and run following commands for PHP7.0 on Ubuntu 16.4

sudo apt-get install mcrypt php7.0-mcrypt
sudo service apache2 restart
3

php7 have mcrypt, you can enable it in php.ini and then everything will work fine.

fico7489
  • 7,931
  • 7
  • 55
  • 89
  • 4
    Can you please elaborate how I install `PHP7 Mcrypt`? I tried to find if `PHP7` has any `Mcrypt` extension, but to no avail. `PHP5` had `Mcrypt` as `php5-mcrypt` which can be enabled and disabled easily with `php5enmod` and `php5dismod` respectively. – Bishal Paudel Dec 04 '15 at 16:06
  • 1
    In /etc/php/7.0/cli/conf.d/20-mcrypt.ini you have to check that the extension is enabled: extension=mcrypt.so and not ;extension=mcrypt.so – user3707264 Sep 29 '16 at 12:33
2

do like this:

  1. wget http://jp2.php.net/distributions/php-7.0.3.tar.gz
  2. tar zxf php-7.0.3.tar.gz
  3. cd php-7.0.3/ext/mcrypt
  4. /php7-path/bin/phpize (when error such as configure: error: mcrypt.h not found. Please reinstall libmcrypt run apt-get install libmcrypt-dev)
  5. ./configure --with-php-config=/php7-path/bin/php-config
  6. (sudo) make && make install .this will install the mcrypt.so in php-7.0.3/ext/mcrypt/modules
  7. cp to the /usr/lib/php/20151012/ what is the shared extensions dir
  8. create a mcrypt.ini in /etc/php/mods-available/ write as extension=mcrypt.so
  9. create link to this such as sudo ln -s /etc/php/mods-available/mcrypt.ini 20-mcrypt.ini in /etc/php/7.0/fpm/conf.d
  10. create link to this such as sudo ln -s /etc/php/mods-available/mcrypt.ini 20-mcrypt.ini in /etc/php/7.0/cli/conf.d
  11. sudo service nginx restart
  12. sudo service php7.0-fpm restart
  13. yes it is.
Fabio Antunes
  • 22,251
  • 15
  • 81
  • 96
devqin
  • 21
  • 6
  • This worked for me when the ppa for installation via apt-get was failing, so thanks! Would be great if you could fix the formatting in your answer though as it's a little hard to follow. – Tom Davies May 11 '16 at 21:49
1

I use, Dotdeb, an extra repository providing up-to-date all kinds of cool toys for your Debian servers like Nginx, PHP, MySQL, Redis etc.

  1. Update your sources.list

    deb http://packages.dotdeb.org {distribution} all 
    deb-src http://packages.dotdeb.org {distribution} all
    
  2. GnuPG keys

    wget https://www.dotdeb.org/dotdeb.gpg
    sudo apt-key add dotdeb.gpg
    
  3. Update apt & build something amazing.

    sudo apt-get update
    
0

PHP7 contains mcrypt extension internally (source-path/ext/mcrypt/). But it depends on Libmcrypt soft.

Step 1.

Download libmcrypt-x.x.tar.gz from http://mcrypt.sourceforge.net/ and build it.

cd libmcrypt-x.x
./configure
make
make install

Step 2.

Rebuild PHP7 from source and add --with-mcrypt option.

./configure ... --with-mcrypt

Other way without rebuilding PHP7

cd php7-source-path/ext/mcrypt/
/php7-path/bin/phpize
./configure --with-php-config=/php7-path/bin/php-config
make && make install
echo "extension=mcrypt.so" >> /php7-path/ext/php.ini

Restart php

Tieme
  • 62,602
  • 20
  • 102
  • 156
eaglewu
  • 458
  • 5
  • 12