Just upgraded to PHP 7 and your Laravel 5 app stopped working? Get errors like this?

ErrorException in EncryptionServiceProvider.php line 16: Use of undefined constant MCRYPT_RIJNDAEL_128 - assumed 'MCRYPT_RIJNDAEL_128'

This post shows how to fix it.

Laravel 5.0 uses mcrypt extension which was finally removed from PHP7. That’s why you get errors. In order to fix it you have 2 options:

1) Upgrade Laravel 5 and your application to the latest version (http://laravel.com/docs/master/upgrade). It’s pretty tedious process, but should be done anyway.

2) Or you can use fake mcrypt extension, to make Laravel think mcrypt is present.
Install laravel-mcrypt-faker

composer require --ignore-platform-reqs thomaswelton/laravel-mcrypt-faker

Note that we use –ignore-platform-reqs otherwise you’ll get errors like

Your requirements could not be resolved to an installable set of packages.
Problem 1
- laravel/framework v5.0.33 requires ext-mcrypt * -> the requested PHP extension mcrypt is missing from your system.

Then open your config/app.php file and comment out Illuminate\Encryption\EncryptionServiceProvider in the providers list.

Replace it with either Thomaswelton\LaravelMcryptFaker\NoEncryptionServiceProvider or Thomaswelton\LaravelMcryptFaker\OpensslEncryptionServiceProvider.

NoEncryptionServiceProvider provides no encryption at all. Set cipher variable in config/app.php to null (i.e. no encryption). Don’t use it for production.

OpensslEncryptionServiceProvider encrypts data using defuse/php-encryption package. In order to use it, you have to regenerate app key

php artisan key:generate-openssl

This should fix the problem.