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: https://github.com/tomgrohl/laravel4-php71-encrypter. 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.
Step 1 — Install my Encrypter
Follow the simple install here: https://github.com/tomgrohl/laravel4-php71-encrypter
Step 2 — TEST!
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.
Step 3 — Upgrade PHP to 7.2 and Pecl
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.
Step 4 — Install Mcrypt Extension
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:
- Pecl Channel needs updating
- 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.
Step 5 — Test….Again !
Once the above is done and your web server restart (php-fpm, apache etc) your application should be running on PHP 7.2!