Making Laravel 4.2 work with PHP 7.2

For people that can’t migrate away from Laravel 4.2 they still want to be able to use the latest version of PHP, if not for the features but for the speed benefits.


Mcrypt was removed in PHP 7.2 and can be installed using pecl. Laravel has a hardcoded check for the mcrypt extension, plus the Encrypter uses mcrypt constants.

The Encrypter (and many of Laravel’s components) aren’t interfaced, so you can’t just drop in a replacement. I ported the Laravel 5 Encrypter into a package that supports PHP 5.6 and 7.1. See: But as that has to extend Laravel’s theirs uses mcrypt constants so you would get errors.


So you want to make sure your on the latest version of Laravel 4.2, because Taylor did release a version to support PHP 7 Throwables. You’ll want to be on PHP 5.6 or 7.0 before starting these steps.

Follow the simple install here:

Test the application works fine with the encrypter. Unless your using it yourself it will just get used by cookies, so test your sessions still work.

You now need to upgrade PHP to 7.2 and also upgrade Pecl. I’ll leave out instructions for this as it will differ depending on the OS you’re using.

If you’ve done this as part of Step 3 you can skip this.

Now you might be asking why I need to install the extension. For me this seemed the easier solution without hacking apart Laravel. With the limited extensibility of the components this seemed the best solution. So even though we’re installing it we won’t be using it.

sudo pecl install mcrypt-1.0.1

You may find this fails for various reasons:

  1. Pecl Channel needs updating
  2. libmcrypt-dev needs upating

This all depending on your OS. The above will probably need doing for Red Hat/Centos and Ubuntu.

The Laravel Encrypter port uses openssl which is better than Mcrypt.

Once the above is done and your web server restart (php-fpm, apache etc) your application should be running on PHP 7.2!

PHP and JavaScript hacker. Symfony and Laravel tinkerer. Creator of TomahawkPHP

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store