Search code examples
laravelhomesteadmcrypt

How to enable php-Mcrypt extension in Laravel Homestead


I am trying to get an old Laravel 4.1.x app up and running again so that it can be modernized. This requires an environment with PHP 5.6 and the Mcrypt extension. I have installed Homestead 9.0.3 (the latest stable version). Within the VM, I have set the PHP version to 5.6

sudo update-alternatives --config php

I have then installed the php-mcrypt extension

sudo apt-get install php5.6-mcrypt

I am now able to create a new Laravel 4.1.x project, which is a process that requires Mcrypt to complete, so we're certainly getting somewhere:

composer create-project laravel/laravel="4.1.*" myAppName

However, when I browse to the webpage for myAppName, I see the message:

Mcrypt PHP extension required.

I have also tried steps that are usually recommended for this problem, ie:

sudo ln -s /etc/php/5.6/conf.d/mcrypt.ini /etc/php/5.6/mods-available/mcrypt.ini
sudo phpenmod mcrypt
sudo service php5.6-fpm restart

But I still get the same message in the browser.

What step have I missed?


Solution

  • Because all the PHP versions installed on homestead you need to set the PHP version for a site in the Homestead.yaml.

    First check what version the server is running with phpinfo();

    Check the file /etc/nginx/sites-enabled/homestead.test and look for this line:

    fastcgi_pass unix:/var/run/php/php5.6-fpm.sock;
    

    If you didn't set the php version on the sites list, this file will be pointing to the php7.3.sock. In this case the version 5.6 has mcrypt installed, but 7.3 don't.

    You can just replace the line

    fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
    

    for

    fastcgi_pass unix:/var/run/php/php5.6-fpm.sock;
    

    and then reload nginx with sudo nginx -s reload.

    Or set the php version on Homestead.yaml:

    sites:
    - map: homestead.test
      to: /home/vagrant/code/public
      php: "5.6"
    

    And then run vagrant provision, it will change the nginx configuration for PHP 5.6.