Laravel 4.2 integration with PHP 7.4 in macOS

Run Laravel 4.2 legacy projects with PHP 7.4

Prerequisite

PHP 7.4 should be installed locally.

Update to Laravel 4.2.22

The first step in integrating PHP 7.4 with your Laravel 4.2 project is to update it to Laravel 4.2.22. This has support for PHP 7 and up. Link to release is provided here.

Code Compatibility

Conduct inspection on your code base to see if your PHP code is compatible with PHP 7.4. For reference, you can check the PHP change logs.

Code Compatibility

Add the line of code below to your app/config/app.php file. This is to intercept deprecated errors for mcrypt. It might not be a good idea but we are already trying to run some deprecated code consciously.

<?php
error_reporting(E_ALL ^ E_DEPRECATED);
...
?>

Installing mcrypt extension

  1. Install mcrypt using Homebrew and PECL (comes with PHP)

    $ brew install mcrypt
    $ pecl install mcrypt-1.0.3
    
  2. Find your php.ini (actual path may vary)

    $ php -i | grep "Loaded Configuration File"
    Loaded Configuration File => **/usr/local/etc/php/7.4/php.ini**
    
  3. Add this line to your php.ini (actual path may vary)

    extension=/usr/local/Cellar/php/7.4.x/pecl/20180731/mcrypt.so
    

That's about it! You can now run your legacy Laravel 4.2 project with PHP 7.4!

References: