It's a very good article for those who are still using Laravel 4.2. and wishes to upgrade PHP 7.x as mcrypt extension is no longer supported in PHP 7.x, while Laravel 4.2 requires it.
I'm porting the copy of the article in case this blog post gets deleted from https://ysbilgin.medium.com/running-laravel-4-2-project-on-php-7-3-or-7-4-b18e41caa0b
I also add few additional helpful things that I found along the way while upgrading the PHP7 to make it work with Laravel 4.2 even better.
Running Laravel 4.2 Project on PHP 7.3 or 7.4
by Yavuz Selim Bilgin on Dec 1, 2019
I have some legacy Laravel 4.2 projects running on PHP 7.1, and PHP 7.1 is no longer supported. (https://twitter.com/krakjoe/status/1201010799034195968?s=12) and then I decided to upgrade them to latest PHP 7.4
ProblemLaravel 4.2 requires mcrypt extension which is deprecated in PHP 7.1 and removed in PHP 7.2.
SolutionLaravel 4.2 has a release for PHP 7, and you can install mcrypt for ≥ 7.2 by PECL.
Step 1: Update Laravel to 4.2.22
Taylor has published a release for PHP 7 compatibility. Update your Laravel to 4.2.22 https://github.com/laravel/framework/releases/tag/v4.2.22
Step 2: Check your code compatibility
First you must be sure about your Laravel 4.2 code is compatible with PHP 7.4. You can check PHP change logs.
Step 3: Disable deprecated errors (optional)
Add the line below to your app/config/app.php because you will get deprecated errors for mcrypt. It might not be a good idea but we are already trying to run some deprecated code consciously. Alternatively you can install https://github.com/tomgrohl/laravel4-php71-encrypter package.
# /app/config/app.php error_reporting(E_ALL ^ E_DEPRECATED);
Step 4: Install and enable mcrypt extension
Install mcrypt extension on your PHP server with PECL.
$ sudo pecl install mcrypt
Step 5: Better Error Handling
PHP v7 introduces ParseError if there's any runtime exception and Laravel 4 has no PHP7 support, so it does not log/display the actual source/cause of the error. It is impossible debug and fix any problem without knowing exactly what caused the error so you either have to upgrade Laravel to 5 for PHP7 support or downgrade PHP to 5.6. However, there's a workaround for using PHP7 with Laravel 4 by disabling the Laravel error handler, which can be done by adding the following 2 lines of code in app/config/app.php right after the <?php
# /app/config/app.php set_error_handler(null); set_exception_handler(null);
Step 6: Test it!
Now, it might be ready but it’s better you test it again. Then you’re ready to run your legacy Laravel 4.2 code on latest PHP 7.4 and get all updates including security ones.